shell脚本实现邮箱报警

配置环境发送邮箱环境

[root@localhost ~]# yum -y install mailx
[root@localhost ~]# vim /etc/mail.rc
在文件的最下方添加以下几条
set from=***********@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=*********@qq.com
set smtp-auth-password=phkmhskdybdxefci
set smtp-auth=login

编写txt文件 里面存储监控的域名

[root@localhost ~]# vim url.txt
www.baidu.com
www.qq.com
www.ahdahfioahwfwsjfbsfb.com

编写脚本

[root@localhost ~]# vim /root/yxbj.sh
#!/bin/bash
website=$(cat url.txt)
for i in $website
do
        code=$(curl -I -m 1 -o /dev/null -s -w %{
    
    http_code} $i)
        if [ $code -eq 200 ];then
                echo "$i is ok"
        else
                echo "$i is not ok,please check!!"
                echo "$i is not ok,please check!!"|mail -s "url check" ***********@qq.com
        fi
done

执行脚本

[root@localhost ~]# sh /root/bj.sh

猜你喜欢

转载自blog.csdn.net/qq_46023525/article/details/106818708