"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 ---***---***---***---***---***---***---***---***---***---***---***---