--- abhishek jain <[EMAIL PROTECTED]> wrote:

> Dear Friends,
> I again have a question(looks like i have a lot of questions:) )
> I need  a shell script run as a cron to do the following task,
> 1)Do 'ps -ef' or with other arguments of 'ps '  and see whether a
> particular  process is executing. Pl. tell me what are the best parameters
> of 'ps' to search for a particular process
> 2) If yes do nothing.
> 3)If no runs that same process.
>  4)Logs all messages to a file
> 5)Logs all error messages to another file.
> I am a novice at shell script.
> Pl. help me give some inputs , regarding the best parameters /arguments of
> 'ps' and whas the method of logging error and normal messages.


try the following code. Hope it helps. i checked for httpd

#!/bin/bash

. /etc/rc.d/init.d/functions

PROCESS=httpd
log()
{
        now=`date`
        echo -e "$now$*" | tee >> script.log
}

status $PROCESS
STATE=$?

if  [ $STATE == 0 ]
then
        log " Success: $PROCESS is running on the server"
else
        log " Error: $PROCESS not running. Restarting $PROCESS"
        /etc/init.d/httpd start
fi

exit 0



                
__________________________________________________________ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com

_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi 
http://www.mail-archive.com/[email protected]/

Reply via email to