打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
测试机房网络连通性和延迟(shell脚本)

测试机房网络连通性和延迟(shell脚本)
 
一、生成本机房到各电信、联通、移动、教育网ping和traceroute的数据;另外搜集各个运营商ip全国的ip列表文件为ip.txt;ipedu.txt;ipdx.txt;ipcmcc.txt(移动)
脚本一:
#!/bin/bash 
ping -c 100 $1 > test/temp/temp_$1 
tail -n 3 test/temp/temp_$1 
traceroute $1 
脚本二:做任务计划每隔15分钟执行一次:
#!/bin/bash 
DateTime=`date "+%Y%m%d%H%M"` 
Date=`date "+%Y%m%d"` 
cd ~ 
mkdir -p test/temp 
mkdir -p test/${Date}/wt 
mkdir -p test/${Date}/dx 
mkdir -p test/${Date}/edu 
mkdir -p test/${Date}/cmcc 
while true; do 
read iplist || break ; 
sh ping_tr.sh $iplist >> test/${Date}/wt/$iplist${DateTime}.txt & 
done < ip.txt 
 
while true; do 
read iplist || break ; 
sh ping_tr.sh $iplist >> test/${Date}/edu/$iplist${DateTime}.txt & 
done < ipedu.txt    
 
while true; do 
read iplist || break ; 
sh ping_tr.sh $iplist >> test/${Date}/dx/$iplist${DateTime}.txt & 
done < ipdx.txt 
 
while true; do 
read iplist || exit ; 
sh ping_tr.sh $iplist >> test/${Date}/cmcc/$iplist${DateTime}.txt & 
done < ipcmcc.txt 
 
二、生成数据报告,发邮件到系统运维部
 
cront配置:20,50 7-23 * * * /bin/bash /root/net-monitor.sh
 
#!/bin/bash 
#2011/08/04 
time=`date +%Y%m%d` 
time1=`date +%Y%m%d%H%M  -d  "20 minutes ago"` 
time2=`date +%H:%M -d "20 minutes ago"` 
[ -d /home/larry/vnet/${time} ] || mkdir /home/larry/vnet/${time} 
path='/root/test' 
isp=(dx wt edu cmcc) 
wt='/root/ip.txt' 
dx='/root/ipdx.txt' 
cmcc='/root/ipcmcc.txt' 
edu='/root/ipedu.txt' 
com(){ 
        awk 'BEGIN{print "-------------------------------------"}' 
        awk 'BEGIN{printf "| %-3s| %-16s | %-8s  |\n","ISP","IP","'$time2'"}' 
        awk 'BEGIN{print "-------------------------------------"}' 
for x in ${isp[@]}     
do 
        for i in `eval cat \\$$x` 
        do 
  grep -E \(---\|^rtt\) ${path}/${time}/$x/${i}${time1}.txt | awk 'BEGIN{FS="/| "}NR%2==1{a=$2}NR%2==0{printf "| %-3s| %-16s | %-8s  |\n","'$x'",a,$8}' 
        done 
        awk 'BEGIN{print "-------------------------------------"}' 
done 
 
com > /home/larry/vnet/${time}/${time1}.txt 
 
myip=`ifconfig eth0 |grep 'inet addr'|awk '{print $2}'|awk -F':' '{print $2}'` 
echo "#########################################################################" >> /home/larry/vnet/${time}/${time1}.txt 
echo "Packet Loss" >> /home/larry/vnet/${time}/${time1}.txt 
echo "$time2 o 'clock"  >> /home/larry/vnet/${time}/${time1}.txt 
grep 'packet loss' /root/test/${time}/*/*${time1}.txt |grep -v ' 0% packet loss'|awk -F',' '{print $1 $2 $3}'| awk -F'/' '{print $5 "/" $6}'  >> /home/larry/vnet/${time}/${time1}.txt 
cat /home/larry/vnet/${time}/${time1}.txt 
mail -s "${time1}_$myip  network monitor" sys@ilarry.com -- -f cnc.2@ilarry.com < /home/larry/vnet/${time}/${time1}.txt 
    
报过内容:
-------------------------------------
| ISP| IP               | 22:00     |
-------------------------------------
| dx | 61.144.56.1      | 38.136    |
| dx | 121.15.148.1     | 41.215    |
| dx | 222.177.80.222   | 56.307    |
| dx | 61.132.78.65     | 27.718    |
| dx | 202.96.112.1     | 37.504    |

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Linux shell用法和技巧 | 外刊IT评论网
122.Linux系统和Shell命令行简介,走上数据分析之路
linux shell 脚本攻略学习
iptables简单防攻击脚本(自动过滤白名单)
crt工具批量添加会话
使用Git来获取Android源码(转)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服