I have a script which will be running all the time...it is like a trigger.. wakesup every 10 minutes(trigger.sh) executes, and I want to write another script which monitors this script every one hour and if it finds that trigger script is not running it should start it and exit...and here is what i could think of doing..
try and grep the script name in the process to see if it is running like..
ps -ef | grep "trigger.sh"
but this is not working....I do not know why...
is theree any other way to try it out.
Next search the forums for Perderabo's datecalc program.
Have your "check it" code:
Read the logfile, get the date it wrote.
Use datecalc to compare the time now with the time back when the entry was made.
If it was too long ago - restart the trigger
After all sorts googling I narrowed it to this....
ps x | grep "trigger.sh" | awk '{ print $3 }' | grep -ic "A"
this gives me the number of active process either sleeping or running and it is Active...which should be greater than or equal to 2
BUT
this gives the results only for the current user.....does anybody know how to enhance it so that it can be used for all users....?
Alexop gave the solution to removing the current process - grep -v $$. Without this the process that runs grep "trigger.sh" always shows up. That is your process - the one looking to see if the script is running.
That means if the other process is not running, you have zero found. In your result, the trigger.sh script is not running. If are you positive it is supposed to be running ALL the time, then not finding it means it is not running. Your result of finding your own process and nothing else also means it is not running.
The solution Alexop gave returns 6 if I am not running the script and returns 7 when I am running I noticed that it is showing all the processes that ran