一、安装Mutt
在Ubuntu/debian下安装:
apt-get install mutt -y
apt-get install msmtp -y
其它系统可以在网络上查一下
二、下载监控脚本,将里面的邮件地址改为自己的
wget http://cndo.org/jk.sh
#!/bin/sh
weblist=/root/list.txt
for list in `cat $weblist|grep -E -v "#|^$"`
do
httpcode=`curl -o /dev/null -s -w %{http_code} "$list"`
httptime=`curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total: %{time_total}\n" "$list"|grep time_total|awk -F ":" '{print $2*1000}'`
if [ $httpcode = 200 ]||[ $httpcode = 301 ]||[ $httpcode = 302 ]||[ $httpcode = 403 ]||[ $httpcode = 401 ]
then
echo "$list is checked ok!"
else
echo "$list is down!" | mutt -s "website is down" i@zmrbk.com
fi
if [ $httptime -ge 10000 ]
then
echo "$list is timeout!" | mutt -s "website is timeout" i@zmrbk.com
else
echo "$list is connect ok!"
fi
done
三、在root目录下创建一个list.txt的文本,可以在本地创建好后用winscp上传到vps,里面写上要监控的网址,一行一个。
vi list.txt
http://www.a.com
http://www.b.com
.....
四、添加计划任务,设置每天监控一次状态。
crontab -e
59 23 * * * /bin/sh /root/jk.sh
签名:这个人很懒,什么也没有留下!