Script to restart services, if they are down.
Hello Gurus,
I am desperately looking for all your helps. This is a most importane thing in my life.
I m in need of script which monitor services like apache,mysql,ftp etc and if its down it should restart and send an alert mail.
I am not great in bash script. But, i found the following. It works for a single service.
I just want a combination of this for many service. Some one, please help me.
Very big please.
#!/bin/bash
RESTART="/etc/init.d/apache2 restart"
#path to pgrep command
PGREP="/usr/bin/pgrep"
# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD="httpd"
# find httpd pid
$PGREP ${HTTPD}
if [ $? -ne 0 ] # if apache not running
then
# restart apache
$RESTART
fi
#!/bin/bash
if [ "$(ps aux | grep httpd | wc -l)" -lt "2" ]; then
echo "Mysql is Down" >&2
echo "Starting Mysql using customized script" >& 2
/etc/init.d/apache2 start
fi
Last edited by sabarishks; 10-30-2008 at 09:55 AM.
|