#!/bin/bash loadavg=`uptime | awk '{print $9}'` if [ "$loadavg" = "average:" ] then echo "not this one..." loadavg=`uptime | awk '{print $10}'` fi RESTART="/sbin/service httpd restart" STOP="/sbin/service httpd stop" MAIL="php mail.php ServerRestarted!" MAIL2="php mail.php ServerStopped!" # bash doesn't understand floating point # so convert the number to an interger thisloadavg=`echo $loadavg|awk -F \. '{print $1}'` if [ "$thisloadavg" -ge "20" ]; then echo "Busy - Load Average $loadavg ($thisloadavg) " #httpd -k stop STOP $MAIL2 elif [ "$thisloadavg" -le "1" ]; then echo "Okay - Load Average $loadavg ($thisloadavg) " pgrep httpd if [ $? -ne 0 ] # if apache not running then # restart apache $RESTART $MAIL echo "restart!" else echo "no restart!" fi else echo "waiting...!" fi