Httpd service monitoring port status, determine whether to activate the server according to the port, if the script does not start automatically pull up the service, if the service is running then exit the script; if the port can also be replaced by another service, but the script needs to be adjusted.
#! / bin / bash # every 3 seconds in real-time monitoring HTTP service state services abnormal output alarm information, and try to start the service running normally when prompted. Web = `the netstat-Ant | grep 80 | awk ' {}. 4 Print $ ' | awk -F: ' {}. 4 Print $ ' ` apachelog = / var / log / the httpd / service.log IF [ ' $ Web ' = ' 80 ' ] the then echo " HTTPD is running " the else echo " Web service is restarted " echo " ` date` Web service is restarted . ">> $ apachelog /etc/init.d/httpd Start &> / dev / null SLEEP 2 echo ` DATE ` restart | / usr / sbin / sendmail -v telephoneNumber @ 139 .com> / dev / null fi