Date: Thu, 13 Jan 2011 14:15:02 +0100 From: =?ISO-8859-1?Q?Samuel_Mart=EDn_Moro?= <faust64@gmail.com> To: four.harrisons@googlemail.com Cc: freebsd-questions@freebsd.org Subject: Re: problem with shell script Message-ID: <AANLkTinOArBsL1GqrtHtJNXiEMZEt37XoaGKM9dbhV_2@mail.gmail.com> In-Reply-To: <4d2ef151.4310df0a.25b7.0199@mx.google.com> References: <4d2ef151.4310df0a.25b7.0199@mx.google.com>
next in thread | previous in thread | raw e-mail | index | archive | help
??
as already answered:
ps ax | awk '/[/]slapd /{n++} END{print n}'
searching '[s]lapd' will avoid grep "auto-matching", but would still return
commands like "vim /etc/slapd.conf" or ./myscript-slapd
about pgrep, like the usual grep, it needs a better expression than the
process name, otherwise it would return the same results as a grep
however, a perfect match may be done looking for the exact path
('[/]usr/local/bin/slapd '), but would still fail when, for ex. running
`objdump /usr/local/bin/slapd -x'
also, if you want to count the number of outputed lines, using [p]grep and
wc makes two processes, while awk can do it all alone.
awk ftw!
On Wed, Jan 12, 2011 at 3:17 PM, <four.harrisons@googlemail.com> wrote:
> Hello
>
> 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=3D0
> SD=3D`ps -ax | grep slapd | grep -v grep | wc -l`
> echo $SD
>
> the result is 3 !!!
>
>
> Any info welcome !
>
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe@freebsd.org"
>
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe@freebsd.org"
>
--=20
Samuel Mart=EDn Moro
{EPITECH.} 2011
CamTrace S.A.S
"Nobody wants to say how this works.
Maybe nobody knows ..."
Xorg.conf(5)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTinOArBsL1GqrtHtJNXiEMZEt37XoaGKM9dbhV_2>
