I would like to setup a Cron job to check weather X process is running or not. if it is not running then start that X process with a log message....
can any one help writing a script?
thanks
I would like to setup a Cron job to check weather X process is running or not. if it is not running then start that X process with a log message....
can any one help writing a script?
thanks
if ! ps -ef | grep process | grep -v grep; then
if start process; then
logger local1.info process started
else
logger local1.err unable to start process
fi
fi
#!/usr/bin/bash
#set environment
logfile=/export/home/log/restart.log
PID=`ps -eo 'tty pid args' | grep 'processname' | grep -v grep | tr -s ' ' | cut -f2 -d ' '`
if [ -z "$PID" ]
then
#Run the process
echo "Started Process at `date`" >> $logfile
else
echo "Process is already Running with PIS=$PID"
fi
Thank you very much!