down机发短信通知

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/bash
#check_down

check_date=`date +%Y/%m/%d" "%k:%M`
check_ip=/root/zhubo/script/check_ip.txt
check_phone=/root/zhubo/script/check_phone.txt

YES=""
NO="warning"

#发短信函数 参数:ip  短信内容
function message () {
        for i in `cat $check_phone` 
        do
                wget -c -q -O /dev/null  "http://短信接口需要购买&mobile=$i&content=${1}${2}${check_date}"
        done
}

#能ping通运行函数
function succ () {
        if [ `grep 'warning' -o /root/zhubo/script/log/$1 | wc -l` -ge 1 ] 
                then 
                message "$1" ",已经开机运行"
                echo ${YES} > /root/zhubo/script/log/$1 
        fi
}

#无法ping通运行函数
function fail () {
        if [ `grep 'warning' -o /root/zhubo/script/log/$1 | wc -l` -ge 5 ]
                then exit 1
        elif [ `grep 'warning' -o /root/zhubo/script/log/$1 | wc -l` -ge 0 ]
                then echo ${NO} > /root/zhubo/script/log/$1
        else
                exit 1
        fi
}

#创建日志文件
for i in `cat ${check_ip}`
do 
        touch /root/zhubo/script/log/$i
done

#判断是否ping通
for i in `cat ${check_ip}`
do
        ping -t 2 -c 1 $i > /dev/null &&  succ $i || fail $i 
done
#发短信通知
for i in `cat ${check_ip}`
do
        if [ `grep 'warning' -o /root/zhubo/script/log/$i | wc -l` -gt 0 ]
                then    if [ `grep 'warning' -o /root/zhubo/script/log/$i | wc -l` -le 5  ]
                                then message $i "is Down ,Please timely treat it."
                        fi
        fi
done