xshell 脚本网站域名监控-邮件提醒

本文介绍了如何利用xshell创建脚本,监控网站域名状态,并通过crontab设置定时任务,实现每隔3分钟检查一次,当服务未启动时发送邮件提醒。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/sh 
weblist="/usr/test/weblist.txt"
myemail="xxxxx@163.com"
 
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 ]
then echo "$list is-1 checked ok!-LianJieZhengChang"
else
echo "$list Warning-Error-FangWenShiBai-"
echo "$list is-down!-FangWenShiBai"| mutt -s "Warning: down" $myemail
fi
 
if [ $httptime -ge 5000 ]
then echo "$list is-3 timeout!-LianJieChaoShi" | mutt -s "Warning: timeout!-WangLuoChaoShi" $myemail
else echo "$list is connect ok!"

fi

 done


-----------------------------------

list.txt

http://www.jquerycn.cn
http://www.dingxinzc.com


-----------

计划任务


crontab -e
*/3 * * * * /bin/sh  /usr/test/webcheck.sh


# /bin/sh 执行命令
# crontab -l 查看是否创建成功
# ps -ax | grep cron  查看服务是否已启动
#*/15 * * * * ls


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值