problem with shell script

Ryuichiro Hara rhml at kibug.org
Wed Jan 12 16:42:32 UTC 2011


(2011/01/13 01:00), Warren Block wrote:
> On Wed, 12 Jan 2011, Samuel Mart?n Moro wrote:
>
>> On Wed, Jan 12, 2011 at 3:50 PM, Chad Kellerman <sunckell at gmail.com> 
>> wrote:
>>
>>> On Wed, Jan 12, 2011 at 9:01 AM, Frank Bonnet <f.bonnet at esiee.fr> 
>>> wrote:
>>>
>>>> I'm in trouble with a simple shell script that give
>>>> erroneous value when running ...
>>>>
>>>> If I run commands interactively everything runs well
>>>>
>>>>> ps ax | grep slapd | grep -v grep | wc -l
>>>>      1
>>>>
>>>> If I run in the following shell script :
>>>>
>>>> #!/bin/sh
>>>> SD=0
>>>> SD=`ps -ax | grep slapd | grep -v grep | wc -l`
>>>> echo $SD
>>>>
>>>> the result is 3 !!!
>>>
>> ps ax | grep "[/]slapd " | wc -l
>> may not fix the problem
>> but still cleaner
>
> ps axc | grep slapd | wc -l
>
> is a little neater.
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to 
> "freebsd-questions-unsubscribe at freebsd.org"

hello.

i would rather use pgrep(1);
pgrep -afl slapd
for just counting purpose,
pgrep -a slapd | wc -l
is enough. i believe it should work all right as expected in `` output, 
as well.



More information about the freebsd-questions mailing list