Check if trigger Script is running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check if trigger Script is running
# 1  
Old 04-03-2006
Check if trigger Script is running

HI,

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.

Thanks,
# 2  
Old 04-03-2006
Have your trigger script write to a log
Code:
> logfile
echo "`date`" > logfile

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
# 3  
Old 04-04-2006
HI,
Please provide u r script which u used to monitor trigger.sh
# 4  
Old 04-04-2006
This should do the trick...

if [[ `ps -ef | grep -v $$ | grep -c trigger.sh` -ne 1 ]]; then
#do whatever you feel appropriate
fi
# 5  
Old 04-04-2006
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....?

Thanks,
# 6  
Old 04-04-2006
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.
# 7  
Old 04-04-2006
Hi,

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

this is what I get when that command ....
Code:
before running my trigger script ...
ps -ef | grep -v $$ | grep Trigger.sh
user1051  610404 1249490   0 09:29:11  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 1474632 1249490   0 09:30:59  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 2003114 1249490   0 09:27:59  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 2031834 1945810   0 10:02:56  pts/8  0:00 /usr/bin/sh ./Trigger.sh
user1051 2293766 1249490   0 09:46:03  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 2314464 1945810   0 11:34:41  pts/8  0:00 /usr/bin/sh ./Trigger.sh

while running Trigger script...
user1051 233596 1249490   0 09:50:12  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 610404 1249490   0 09:29:11  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 1474632 1249490   0 09:30:59  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 2003114 1249490   0 09:27:59  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 2031834 1945810   0 10:02:56  pts/8  0:00 /usr/bin/sh ./Trigger.sh
user1051 2293766 1249490   0 09:46:03  pts/3  0:00 /usr/bin/sh ./Trigger.sh
user1051 2314464 1945810   0 11:34:41  pts/8  0:00 /usr/bin/sh ./Trigger.sh

This could be because I ran the script for a while and stopped it and ran again, then it counts all the processes including the current one.....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to check if the script is already running?

I have one shell script in NAS shared location. Since NAS is mounted in many servers, script can be run from any of those servers. I want to make sure if the script is already running, it should not allow others to run it. I googled it and got some idea that i can touch one empty file in the... (8 Replies)
Discussion started by: thomasraj87
8 Replies

2. Shell Programming and Scripting

Check to see if script is already running

Happy New Year Is there a quick way to check to see if a script is already running. I want to put in a check in the script to exit, if already running. Currerntly i can only think of doing it the following way. # ps -ef | grep -i 3_HOUSEKEEPING_FFTVTL_TO_FFTDSSU_DUPLICATION.ksh |... (5 Replies)
Discussion started by: Junes
5 Replies

3. Shell Programming and Scripting

Check presence of trigger file

Hi, I make a sftp connection successfully.My requirement is the script shall execute only after i find a trigger file(dailyreport.OK.psv) in the remote dir. If the trigger file is not present ,the script should exit else it should continue with the rest of the scripts statements. Below code is... (13 Replies)
Discussion started by: samrat dutta
13 Replies

4. UNIX for Dummies Questions & Answers

[Solved] How to Check if a script is running?

Hi All, I am new to Unix... Can you please let me know how we can check if a script is running or not on Solaris box? (4 Replies)
Discussion started by: Rahul466
4 Replies

5. Shell Programming and Scripting

Script to check running of process

Hi, Can anyone please tell me how to write a shell script to check whether a process if running or not.... if its still running then wait for sometime and if not then run the next query. Also, Under my one main script main.sh I have to run 2 scripts simutaneously which take some time to... (2 Replies)
Discussion started by: lovepujain
2 Replies

6. UNIX for Dummies Questions & Answers

Help Running a Check in Bash Script

Hey guys, so I wrote a small script that pretty much just takes in two numbers and counts from the first to the second, e.g. unknown-hacker|544> count.sh 1 3 1 2 3 My problem is I want to make it so that if you input invalid parameters, such as non-numerical characters, more than 2... (2 Replies)
Discussion started by: Duo11
2 Replies

7. Shell Programming and Scripting

script to check if another script is running and if so, then sleep for sometime and check again

Hi, I am a unix newbie. I need to write a script to check wheteher another script is still running. If it is, then sleep for 30m and then check again if the script is running. If the script has stopped running then, I need to come out of the loop. I am using RHEL 5.2 (2 Replies)
Discussion started by: mathews
2 Replies

8. Shell Programming and Scripting

script to check if process is running

How do I make a shell script to see if a certain process is running. The process shows up on ps aux as /usr/sbin/daemon eg: if /usr/sbin/daemon else #nothin basically i want to run the process if it isnt running/ has been stopped. Thanks. (2 Replies)
Discussion started by: daydreamer
2 Replies

9. Shell Programming and Scripting

Running a check platform script

Hi, I want to run a check platform & application script under ksh (Soaris boxes). It runs some commands and it take some time. I want to customize it like that: - output is too big, hence I want some output of the commands to be redirect ed in an output file (or maybe two or three) - not... (4 Replies)
Discussion started by: heartwork
4 Replies

10. Shell Programming and Scripting

check that script is not running twice

using ps -ef | fgrep "ld_data" how do i write a script to check that it didn't already run Thanks (2 Replies)
Discussion started by: Link_02
2 Replies
Login or Register to Ask a Question