Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Location
    Germany
    Posts
    5

    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

  2. #2
    Linux 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.

    Code:
    ps -ef | grep \./DBTest | grep -v -w $$ | wc -l
    Also '.' means match any character to grep so escape it as I did to search specifically for a dot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •