Web site Server monitoring mail alert configuration
Because some of the Web site old server still use 2003 system, often appear in the server paging is full, server memory overflow and so on, resulting in the entire server Web station can not open the situation, the server too much tracing difficult, sometimes difficult to find timely processing, affecting customer experience. So the individual wrote a mail alarm shell, when the overall server can not be opened, timely mail alarm notification.
The first thing is to install a Linux, and then install the MAILX mail system.
Can be used: Yum install mailx–y installed, which has been installed here by viewing.
Configure the messaging system to send and receive settings: Use 163 mail here, feel more convenient.
Vim/etc/mail.rc
Add the following settings:
Write a shell script: monitor.sh
#!/bin/bash
Author by Jerry (2011-2019)
Rm-rf/server/script/log.txt
For line incat -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
status=curl -sI $domains |grep "200 OK" |awk ‘{print $2}‘
["$status"! = "$"] && 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"! = "$"] && echo "Message Server $hostip report error,pls Check It $status" |mail-s "$hostip Warnni ng $localtime "[email protected]
Done
Note: Ip.txt is the server Ip address and the Web site used to detect the service.
Then add the task schedule settings: 15 minute detection, can be set as needed.
Vim/etc/crontab
Add the following settings:
/15 * root/server/script/monitor.sh
Log.txt is a recorded detection condition:
200 value is normal, the detection station only set 200, not normal will send mail:
Email Alert effect:
Web site Server monitoring mail alarm configuration of several server mail alarm settings [III]