ルームネットワークの接続性と遅延をテストする(shellスクリプト)
10818 ワード
一、本機械室から各電信、聯通、移動、教育網pingとtracerouteまでのデータを生成する.また、各キャリアipの全国のipリストを収集するファイルはipである.txt;ipedu.txt;ipdx.txt;ipcmcc.txt(移動)
シナリオ1:
シナリオ1:
- #!/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 |
","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 |
","'$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" [email protected] -- -f [email protected] < /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 |
| dx | 61.130.152.34 | 39.633 |
| dx | 61.132.128.1 | 24.814 |
| dx | 202.105.177.100 | 44.165 |
-------------------------------------
| wt | 116.114.16.58 | 21.583 |
| wt | 218.56.56.1 | 17.534 |
| wt | 125.39.101.1 | 28.832 |
| wt | 218.12.255.186 | 11.877 |
| wt | 58.23.128.22 | 79.854 |
| wt | 202.102.245.71 | 13.890 |
| wt | 120.80.2.106 | 70.563 |
| wt | 221.10.28.1 | 38.923 |
| wt | 221.5.247.1 | 38.667 |
| wt | 58.20.125.210 | 64.651 |
| wt | 58.19.238.1 | 26.398 |
-------------------------------------
| cmcc| 218.202.1.188 | 100.263 |
| cmcc| 218.204.81.1 | 51.917 |
| cmcc| 218.206.191.1 | 41.055 |
| cmcc| 221.130.13.13 | 36.846 |
-------------------------------------
#######################################################
Packet Loss
22:00 o 'clock
cmcc/120.203.214.177201201032200.txt:100 packets transmitted 99 received 1% packet loss
cmcc/218.201.21.158201201032200.txt:100 packets transmitted 95 received 5% packet loss
dx/222.217.99.18201201032200.txt:100 packets transmitted 96 received 4% packet loss
dx/61.139.48.66201201032200.txt:100 packets transmitted 0 received 100% packet loss
edu/115.156.255.14201201032200.txt:100 packets transmitted 96 received 4% packet loss
edu/202.112.49.1201201032200.txt:100 packets transmitted 99 received 1% packet loss
edu/202.175.26.214201201032200.txt:100 packets transmitted 99 received 1% packet loss
edu/202.179.240.1201201032200.txt:100 packets transmitted 94 received 6% packet loss
edu/210.40.119.22201201032200.txt:100 packets transmitted 48 received 52% packet loss
edu/59.75.1.1201201032200.txt:100 packets transmitted 99 received 1% packet loss
wt/120.80.2.106201201032200.txt:100 packets transmitted 99 received 1% packet loss