天天看點

腳本練習_每 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 檔案中