Greetings! I have a script that is run by cron every hour. I want to create a conditional statement that will check to see if the script is already running and to exit if the script is found in the output of 'ps x'. The conditional statement I'm working on is: test $(ps x | grep "/bin/bash /root/scripts/setiathome") || exit 1 When I run the following grep command, I get two matches: server:~ # ps x | grep "/bin/bash /root/scripts/setiathome" 9436 pts/0 S 0:00 /bin/bash /root/scripts/setiathome 9445 pts/0 S 0:00 grep /bin/bash /root/scripts/setiathome The first match (process 9436) is what I'm testing for. If the first match is not running, grep exits with a zero since the second match is found. How do I eliminate the second match? Thanks! Christopher Reimer
"Christopher D. Reimer" wrote:
Greetings!
I have a script that is run by cron every hour. I want to create a conditional statement that will check to see if the script is already running and to exit if the script is found in the output of 'ps x'.
The conditional statement I'm working on is:
test $(ps x | grep "/bin/bash /root/scripts/setiathome") || exit 1
When I run the following grep command, I get two matches:
server:~ # ps x | grep "/bin/bash /root/scripts/setiathome" 9436 pts/0 S 0:00 /bin/bash /root/scripts/setiathome 9445 pts/0 S 0:00 grep /bin/bash /root/scripts/setiathome
The first match (process 9436) is what I'm testing for. If the first match is not running, grep exits with a zero since the second match is found. How do I eliminate the second match?
Hi Christopher, Try: ps x | grep "/bin/bash /root/scripts/setiathome" | grep -v "grep" as your conditional test. The last part tells grep to ignore any line containing "grep". HTH, Richard -- << How can anybody be enlightened? >> << Truth is after all, so poorly lit. >> -- Neil Peart ---***---***---***---***---***---***---***---***---***---***---***--- Richard Witt Phone: (330) 672-0096 Dept. of Physics, Kent State University Email: witt@cnr2.kent.edu ---***---***---***---***---***---***---***---***---***---***---***---
At 09:38 AM 3/19/2001, Richard Witt wrote:
Try:
ps x | grep "/bin/bash /root/scripts/setiathome" | grep -v "grep"
as your conditional test. The last part tells grep to ignore any line containing "grep".
Thanks! I thought I was missing something obvious. :) Christopher Reimer
On Mon, 19 Mar 2001 12:07:17 -0800, Christopher D. Reimer said: | At 09:38 AM 3/19/2001, Richard Witt wrote: | | > Try: | > | > ps x | grep "/bin/bash /root/scripts/setiathome" | grep -v "grep" | > | >as your conditional test. The last part tells grep to ignore any line | >containing "grep". | | Thanks! I thought I was missing something obvious. :) | | Christopher Reimer | | Why don't you use a flag file in /var/run? Seems far the best way to handle these kind of things. -- ---------------------------------------------------- Koos Pol T: +31 20 3116122 Systems Administrator F: +31 20 3116200 Compuware Europe B.V. E: koos_pol@nl.compuware.com Amsterdam PGP public key available
On 20 Mar 2001, Koos Pol wrote: kp> Why don't you use a flag file in /var/run? Seems far the best way to kp> handle these kind of things. kp> I've seen instances though, where the "flag" file in /var/run isn't removed though when the program crashes. It's a nice check, but if the program ins't really running, then the "flag" is kinda pointless. kp> -- S.Toms - tomas@primenet.com - www.primenet.com/~tomas SuSE Linux v7.0+ - Kernel 2.2.18 Organic chemistry is the chemistry of carbon compounds. Biochemistry is the study of carbon compounds that crawl. -- Mike Adams
Today, Mar 19, Christopher D. Reimer wrote:
test $(ps x | grep "/bin/bash /root/scripts/setiathome") || exit 1
When I run the following grep command, I get two matches:
server:~ # ps x | grep "/bin/bash /root/scripts/setiathome" 9436 pts/0 S 0:00 /bin/bash /root/scripts/setiathome 9445 pts/0 S 0:00 grep /bin/bash /root/scripts/setiathome
The first match (process 9436) is what I'm testing for. If the first match is not running, grep exits with a zero since the second match is found. How do I eliminate the second match?
ps x | grep ["/bin/bash "]/root/scripts/setiathome Ken
participants (5)
-
Christopher D. Reimer
-
Ken Hughes
-
Koos Pol
-
Richard Witt
-
S.Toms