Dict.CN 在线词典, 英语学习, 在线翻译

都市淘沙者

荔枝FM Everyone can be host

统计

留言簿(23)

积分与排名

优秀学习网站

友情连接

阅读排行榜

评论排行榜

shell监控服务器alive并自动发短信报警

原帖:http://bbs.linuxtone.org/redirect.php?tid=3325&goto=lastpost
脚本借助了抚琴煮酒测试局域网内主机是否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 [[ -/usr/local/sbin/51edu.txt ]];then
            DOWN
=`cat /usr/local/sbin/51edu.txt|paste --','`
            curl 
"http://sms.api.bz/fetion.php?username=1501*******&password=******& amp;sendto=1501*******&message=$DOWN服务器down机,请尽快处理!"
        fi
      fi
 done

更简洁:
#!/bin/bash
#
Checks to see if hosts 192.168.100.1-192.168.100.16 are alive
#
$?输出命令退出代码:0为命令正常执行,1-255为有出错
for n in {1..16}; do
         host
=192.168.100.$n
         ping 
-c2 $host &>/dev/null
         
if [ $? = 0 ]; then
            echo 
"$host is UP"
         
else
            echo 
"$host is DOWN"
            curl 
"http://sms.api.bz/fetion.php?username=135****&password=***&sendto=135***&message=$host服务器down机,请尽快处理!"
         fi
done


posted on 2009-08-17 18:50 都市淘沙者 阅读(832) 评论(0)  编辑  收藏 所属分类: Linux/OpenVPN/Python


只有注册用户登录后才能发表评论。


网站导航: