天天看点

脚本练习_每 30s 监控主机存活率 邮件报警

#!/bin/bash
# The monitoring host survival script.
# Writen by Wangxiaoqiang 2014-11-24.

HOST=xxx.xxx.x.xx
[email protected]

while true
  do
    ping -c 10 $HOST > /dev/null
    if [ $? -ne 0 ]
      then
        echo "HOST:$HOST down." | mail -s "MAIL FOR $HOSTNAME" $MAIL
    fi
    sleep 30
done

# End

## sh mail.sh &  , 可以将其放入 /etc/rc.local 文件中