WEB站服务器监控邮件报警配置
由于部分WEB站旧服务器仍旧使用2003系统,经常出现服务器内分页大满,服务器内存溢出等情况,导致整台服务器WEB站无法打开的情况,服务器太多寻查难度较大,有时难以及时发现处理,影响客户体验度。于是个人写了一个邮件报警SHELL,当服务器整体无法打开时,及时邮件报警通知。
首先还是要安装一台LINUX,其次安装上MAILX邮件系统。
可以使用:Yum install mailx –y 安装,这里已经安装通过查看。

配置邮件系统收发设置:这里使用163邮件,感觉比较方便。
Vim /etc/mail.rc
加入下列设置项:
写一个SHELL脚本:monitor.sh
#!/bin/bash
author by jerry(2011-2019)
rm -rf /server/script/log.txt
for line in
cat -A /server/script/ip.txt
do
domains=
echo $line |cut -d"^" -f1|awk -F"/" '{print $1}'
hostip=
echo $line |cut -d"^" -f1|awk -F"/" '{print $2}'
status=
curl -sI $domains |grep "200 OK" |awk '{print $2}'
if [ "$status" != "200" ]
then
curl -sI $domains |grep "200 OK" |awk '{print $2}'
[ "$status" != "200" ] && status=
curl -o /dev/null -s -w %{http_code} $domains
fi
echo "$hostip --- $status" >>/server/script/log.txt
localtime=
date +%Y-%m-%d" "%H:%M:%S
[ "$status" != "200" ] && echo "Message Server $hostip Report Error,Pls Check It $status" |mail -s "$hostip warnning $localtime" [email protected]
done
另一种方式脚本写法(推荐使用更高效):
cat -A /server/script/ip.txt
domain=
echo $line |cut -d"/" -f1
echo $line |cut -d"/" -f2|awk -F"$" '{print $1}'
wget --spider -nv $domain -o /server/script/cache
cat /server/script/cache|awk '{print $5}'
ipcount=
awk '{print $3}' /server/script/log.txt |grep 200|wc -l
date +%Y-%m-%d" "%H:%M:%S
[ $ipcount != 34 ] && cat /server/script/log.txt |grep -Ev 200 |mail -s "Message Server warnning $localtime" [email protected]