Script to check status of Apache Mysql and restart if failed

Here's a script to check the status of Apache and MySQL and restart it if its failed:

dt=`date %y-%m-%d---%H:%M:%S`

st=`service apache2 status`

if [[ $st == *NOT* ]]

then

sf="Apache Service FAILED"

echo $dt $sf >> /opt/scripts/status.log

service apache2 stop

service apache2 start

fi

sst=`netstat -lpn | grep 3306`

if [[ $sst == "" ]]

then

ssf="Mysql Service Failed"

echo $dt $ssf >> /opt/scripts/status.log

service mysql start

fi

The script then runs via cron and logs events into a log file it the service had failed.