Linux下shell脚本PING命令只要延迟高于100ms就发送个邮件

#!/bin/bash
Timeout=0;
Timeout_limit=1;
Timeout_flag=0;
IP="8.8.8.8"
                                                                                                                                                                                                
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

你可能感兴趣的:(Linux)