安装邮件报警
[root@localhost ~]# yum -y install mailx[root@localhost ~]# vim /etc/mail.rc###添加###set [email protected] smtp=smtp.qq.comset [email protected] smtp-auth-password=batblstdgotsbbeiset smtp-auth=login
编辑一个存放域名的文档
[root@localhost ~]# vim /tmp/url.txtwww.baidu.comwww.qweqweqwe.com
创建脚本目录
[root@localhost ~]# mkdir /shell
编辑shell脚本
[root@localhost ~]# vim /shell/url.sh#!/bin/bashcheck_web(){web=(`cat /tmp/url.txt`)for url in ${web[@]}docode=$(curl -I -m 5 -s -o /dev/null -w %{http_code} $url)if [ $code -eq 200 ]; thenecho \"$url is ok\"elseecho \"$url is not ok,please check!!\" | mail -s \"url check\" [email protected]}while :docheck_websleep 5done
测试
[root@localhost ~]# vim /shell/url.sh