Linux下shell脚本PING命令只要延迟高于100ms就发送个邮件
#!/bin/bashTimeout=0;Timeout_limit=1;Timeout_flag=0;IP="8.8.8.8"
·
#!/bin/bash
Timeout=0;
Timeout_limit=1;
Timeout_flag=0;
IP="<a href="https://www.baidu.com/s?wd=8.8.8.8&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzPj7-uHTzuWf3rAnsn1-b0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHfkrjm4P1bk" target="_blank" class="baidu-highlight">8.8.8.8</a>"
while [ 1 ]
do
# 取平均延迟的整数位
Timeout="`ping $IP -c 3 | grep 'min/avg/max/mdev'|awk '{print $4}'|cut -b '7'`"
if [ $Timeout -ge $Timeout_limit ] && [ $Timeout_flag -ne 1 ]; then
echo ping timeout, average delay=$Timeout ms
mail -s 'Ping Delay' 邮箱 < ar/log/boot.log
Timeout_flag=1
fi
if [ $Timeout -lt $Timeout_limit ] && [ $Timeout_flag -ne 0 ]; then
echo ping recovery, average delay=$Timeout ms
mail -s 'Ping recovery' 邮箱 < ar/log/boot.log
Timeout_flag=0
fi
sleep 5
done
Timeout=0;
Timeout_limit=1;
Timeout_flag=0;
IP="<a href="https://www.baidu.com/s?wd=8.8.8.8&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzPj7-uHTzuWf3rAnsn1-b0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHfkrjm4P1bk" target="_blank" class="baidu-highlight">8.8.8.8</a>"
while [ 1 ]
do
# 取平均延迟的整数位
Timeout="`ping $IP -c 3 | grep 'min/avg/max/mdev'|awk '{print $4}'|cut -b '7'`"
if [ $Timeout -ge $Timeout_limit ] && [ $Timeout_flag -ne 1 ]; then
echo ping timeout, average delay=$Timeout ms
mail -s 'Ping Delay' 邮箱 < ar/log/boot.log
Timeout_flag=1
fi
if [ $Timeout -lt $Timeout_limit ] && [ $Timeout_flag -ne 0 ]; then
echo ping recovery, average delay=$Timeout ms
mail -s 'Ping recovery' 邮箱 < ar/log/boot.log
Timeout_flag=0
fi
sleep 5
done
更多推荐
已为社区贡献3条内容
所有评论(0)