Here is an example surveillance service httpd port status, according to the port to determine whether the server is started, if not start the script automatically pull up the service, if the service is running exit script program; if the port can also be replaced by another service, but the script needs to be done Adjustment. |
#! / 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.
= `the netstat-Ant Web | 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 [email protected]> / dev / null
fi