#this script can monitor webserver and send message to fanfou and your mobile phone.
#notice:
#1.change you phone number.
#2.the program "sms" is fetion for linux.
server_list=(192.168.0.21:80 192.168.203.1:80)
date=`date +"%y%m%d-%H:%M:%S"`
okmsg=/var/log/okmsg
errormsg=/var/log/errormsg
lockfile=/usr/local/web.Lock
if [ "$UID" -ne 0 ]
then
echo"must be root can run this script.!"
exit
fi
if [ -f $lockfile ]
then
echo "script already runing."&&exit
else
touch $lockfile
fi
send_msg_to_fetion()
{
/usr/local/bin/sms -f 138000000 -p password -t 138000000 -m "$date $msg" -d 1 >/dev/null 2>&1
}
send_msg_to_fanfou()
{
curl -u hackcrisman@gmail.com:password -d status="$date $msg" http://api.fanfou.com/statuses/update.xml >/dev/null 2>&1
}
server_all_num=${#server_list [*]}
i=0
while [ $i -lt $server_all_num ]
do
server_ip=$(echo ${server_list[$i]}|awk -F':' '{print $1}')
server_port=$(echo ${server_list[$i]}|awk -F':' '{print $2}')
if curl -m 10 -G http://${server_list[$i]} > /dev/null 2>&1
then
status=1
echo "服务器${server_ip},端口${server_port}可以正常访问。" >>$okmsg
msg="服务器${server_ip},端口${server_port}可以正常访问。"
else
if ping -c 1 $server_ip >/dev/null 2>&1
then
status=2
echo "服务器${server_ip},端口${server_port}无法访问,但可以Ping 通" >>$errormsg
msg="服务器${server_ip},端口${server_port}无法访问,但可以Ping 通"
else
status=0
echo "服务器${server_ip},端口${server_port}无法访问,且无法Ping 通" >>$errormsg
msg="服务器${server_ip},端口${server_port}无法访问,且无法Ping 通"
fi
fi
send_msg_to_fanfou
send_msg_to_fetion
(( i++))
done
rm -rf $lockfile
#notice:
#1.change you phone number.
#2.the program "sms" is fetion for linux.
server_list=(192.168.0.21:80 192.168.203.1:80)
date=`date +"%y%m%d-%H:%M:%S"`
okmsg=/var/log/okmsg
errormsg=/var/log/errormsg
lockfile=/usr/local/web.Lock
if [ "$UID" -ne 0 ]
then
echo"must be root can run this script.!"
exit
fi
if [ -f $lockfile ]
then
echo "script already runing."&&exit
else
touch $lockfile
fi
send_msg_to_fetion()
{
/usr/local/bin/sms -f 138000000 -p password -t 138000000 -m "$date $msg" -d 1 >/dev/null 2>&1
}
send_msg_to_fanfou()
{
curl -u hackcrisman@gmail.com:password -d status="$date $msg" http://api.fanfou.com/statuses/update.xml >/dev/null 2>&1
}
server_all_num=${#server_list [*]}
i=0
while [ $i -lt $server_all_num ]
do
server_ip=$(echo ${server_list[$i]}|awk -F':' '{print $1}')
server_port=$(echo ${server_list[$i]}|awk -F':' '{print $2}')
if curl -m 10 -G http://${server_list[$i]} > /dev/null 2>&1
then
status=1
echo "服务器${server_ip},端口${server_port}可以正常访问。" >>$okmsg
msg="服务器${server_ip},端口${server_port}可以正常访问。"
else
if ping -c 1 $server_ip >/dev/null 2>&1
then
status=2
echo "服务器${server_ip},端口${server_port}无法访问,但可以Ping 通" >>$errormsg
msg="服务器${server_ip},端口${server_port}无法访问,但可以Ping 通"
else
status=0
echo "服务器${server_ip},端口${server_port}无法访问,且无法Ping 通" >>$errormsg
msg="服务器${server_ip},端口${server_port}无法访问,且无法Ping 通"
fi
fi
send_msg_to_fanfou
send_msg_to_fetion
(( i++))
done
rm -rf $lockfile