- 首页 > 睿知 > it技术 > >
CentOS7利用Mailx发送URL的监控告警邮件
- 安装mailx
#安装
yum install -y mailx#测试
echo "received" | mail -s "test mailx" xx@xx.com
【CentOS7利用Mailx发送URL的监控告警邮件】配置发件信息 /etc/mail.rc
set from=mailaccess
set smtp=smtpserver
set smtp-auth-user=xxx@xx.com
set smtp-auth-password=******
- 添加RUL地址文件
cat urllist
#aa
172.16.111.11
#bb
172.16.111.12
#cc
http://xx.xx.com
- 监控脚本? cat monitor.sh
#!/bin/bash
#监控xxxx
while true
do
Mail="xx@xx.com"
FailCount=0
Retval=0
GetUrlStatus() {
for ((i=1;
i<=3;
i++))
do
wget -T 3 --tries=1 --spider ${1} >/dev/null 2>&1
[ $? -ne 0 ] && let FailCount+=1;
done
Date=`date +%F" "%H:%M`
if [ $FailCount -gt 1 ];
then
Retval=1
echo "check fail!!!,sendmail....."
echo "Date : $Date \n Problem :$urllist服务异常,请尽快处理!" | mailx -v -s "xx监控提醒"$Mailelse
Retval=0
echo "Date : $Date$urllist is running."
fi
return $Retval
}
for url in `cat url | sed '/^#/d'`
do
GetUrlStatus $urllist
done
sleep 60
done
- 启动命令
nohup ./monitorurl.sh >>monitor.log &
推荐阅读