#!/bin/sh datetime=`date +'%Y-%m-%d %H:%M:%S'` proc_http=`/sbin/service httpd status | awk '$1=="httpd"{if($5=="running..."){print "ok"}else{print ;}}'` proc_mysql=`/sbin/service mysqld status | awk '$1=="mysqld"{if($5=="running..."){print "ok"}else{print ;}}'` log="/root/watcher/service.txt" if [ "$proc_http" != "ok" -o "$proc_mysql" != "ok" ] ; then msg="$datetime - the service is abnormal, mysqld is [ $proc_mysql ] and httpd is [ $proc_http ]" if [ "$proc_http" = "ok" -a "$proc_mysql" != "ok" ] ; then echo " - keep httpd service stopping now..." some=`/sbin/service httpd stop | awk '{print $4}'` msg="$msg and keep the httpd service stopped [ $some ]" fi echo "$msg" if [ -f "$log" ] ; then echo " - the last error file exist, skip this time." else echo "$msg" > "$log" python /root/watcher/mail.py >> /root/watcher/mail.log 2>&1 fi else if [ -f "$log" ] ; then echo "$datetime - found error file, clean up ...[ $log ]" rm -f "$log" fi fi