Results 1 to 2 of 2
Hello all,
If I enter the command:
ps -ef | grep ./DBTest | grep -v $$ | wc -l
I get "0" as the output
If I enter xxx=`ps -ef ...
- 10-01-2009 #1Just Joined!
- Join Date
- Jul 2009
- Location
- Germany
- Posts
- 3
Why are different results returned
Hello all,
If I enter the command:
ps -ef | grep ./DBTest | grep -v $$ | wc -l
I get "0" as the output
If I enter xxx=`ps -ef | grep ./DBTest | grep -v $$ | wc -l` or
xxx=$(ps -ef | grep ./DBTest | grep -v $$ | wc -l)
$xxx is set to 1
I am trying to use this logic to allow a program (called DBTest) to only run if there is not a program called DBTest already running.
My suspicion is it is something to do with $$
Cheers
John
- 10-01-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
This is only a guess but the 'grep -v $$' will exclude any line with that number which is the PID. If the ps output for ./DBTest has that number somewhere in its line then that line will be excluded as well. Try using the grep '-w' option.
Also '.' means match any character to grep so escape it as I did to search specifically for a dot.Code:ps -ef | grep \./DBTest | grep -v -w $$ | wc -l


Reply With Quote