- 论坛徽章:
- 0
|
说明:
这个只是想测试IDC 网络的稳定性, 后来经过改进,反现有别的用处.比如监控网络环境,目前还不完善,
希望这个脚本的目标: 能监控路由,并检测某一跳的丢包率, 达到一个阀值后,就发邮件,声音等报警.
最近比较忙,希望哪位朋友, 有时间把它弄的更有实用性.- #!/bin/bash
- #function counter(){
- counter=/tmp/counter
- if test ! -f $counter
- then
- touch $counter
- fi
- read access < $counter
- access=`expr $access + 1`
- echo $access > $counter
-
- # echo $access
- #}
-
- eval `date "+today="%Y"."%m"."%d"' '"%T";"`
- echo -n -e "\033[40;32m"
- printf "===============================================================\n"
- printf "$today $access mtr.sh by iceman.qi\n"
- printf "===============================================================\n"
- echo -n -e "\033[40;37m"
- printf "%-14s %-5s %-6s %-7s %-5s %-3s %-8s %-8s \n" "HOST" "LOSS" "RCVD" "SENT" "BEST" "AVG" "WORST"
- while read line
- do
- set $line
- m=`expr length $1`
- if [ $m -ge 7 -a $m -le 15 ]
- then
- HOST[$n]=$1
- LOSS[$n]=$2
- RCVD[$n]=$3
- SENT[$n]=$4
- BEST[$n]=$5
- AVG[$n]=$6
- fi
- ((n=n+1))
- printf "%-16s %-5s %-6d %-6d %-.2f %-.2f %-.2f %-8s\n" "$1" "$2" "$3" "$4" "$5" "$6" "$7"
- #done < <(mtr -r -n 210.5.159.55 |grep "\%" 2>/dev/null)
- done < <(/usr/sbin/mtr -r -n 210.5.159.55 |grep "\%" )
- echo -n -e "\033[40;32m"
- printf "===============================================================\n"
- printf "===============================================================\n"
- printf "===============================================================\n"
- echo -n -e "\033[40;37m"
- echo ""
复制代码
输出的结果如下: |
|