使用shell脚本,监控远程的一台机器(假设ip为192.168.0.x)的存活状态,当发现宕机时发一封邮件给你自己
- #!/bin/bash
- ip='192.168.0.19'
- mail=aiker@gzedu.ml
- while true
- do
- ping -c4 $ip > /dev/null
- if [ $? -ne 0 ]
- then
- echo "`date +%F-%T` $ip is down" | mail -s " $ip is down" $mail
- fi
- sleep 30
- done