I have requirement. I am running a job every 30mins. before starting the process, i need to check the process, if the process is still running then i need not trigger the process again, if it is not running then trigger the process again. I am using cron to trigger the shell script. Can you please help by telling the exact command. I am new to shell scriptiing.
FIND=`ps -elf | grep "usr_script" | grep -v grep`
if [ $? -eq 0 ]
then
echo "process found'
echo $FIND
FINDPROC=`awk {print $4}` # it reads forth column to find process id
kill -9 $FINDPROC # kills process id of the usr_scirpts procsses
else
echo "process no found"
#start your scirpt here
fi
go through this example
if any problem pls let me know to give proper solution
before checking how to find a process whether it is running in background or not ???? can you check and let us know, how to check whether any process is runnning irrespective of bg or fg ????
This didn't work for me, can anyone see what needs to be changed? Here's my output:
process found
0 S userName 21426 1 0 40 20 ? 14409 ? 15:12:34 pts/2 0:06 rmiregistry 1199
awk: syntax error near line 1
awk: illegal statement near line 1