脚本借助了抚琴煮酒 的测试局域网内主机是否alive的小脚本
http://bbs.linuxtone.org/thread-2065-1-1.html
新加入了飞信免费发短信API接口(可以自己给自己发短信,完全免费)
把ping不同的ip地址写到一个文件里面,并去判断这个文件是否为空来实现报警功能
#!/bin/bash cat /dev/null >/usr/local/sbin/51edu.txt for n in {66..75}; do host=192.168.0.$n ping -c5 $host &>/dev/null if [ $? = 0 ]; then echo "$host is up" >/dev/null else echo "$host" >>/usr/local/sbin/51edu.txt if [[ -s /usr/local/sbin/51edu.txt ]];then DOWN=`cat /usr/local/sbin/51edu.txt|paste -s -d ','` curl "http://sms.api.bz/fetion.php?username=1501*******&password=******&sendto=1501*******&message=$DOWN服务器down机,请尽快处理!" fi fi done