告警邮件监控机器是否存活

#!/bin/bash
ip=66.45.227.244
ma=邮箱地址

while true
do
  n=`ping -c1 $ip 2>/dev/null |grep ‘received’|awk -F ‘received,|%’ ‘{print $2}’`
  if [ -z “$n” ]
  then
    echo “There is sth wrong inthe script.”
  fi
  if [ $n -ge 20 ]
  then
    python /usr/local/sbin/mail1.py $ma “$ip down” “$ip is down”
  fi
sleep 30
done

脚本时死循环,每隔30s检测一次
[ -z “$n” ] 检测是否为空
[ $n -ge 20 ] 检测是否大于20

发表评论