From owner-freebsd-questions@FreeBSD.ORG Thu Jan 13 13:15:44 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AD6EA1065694 for ; Thu, 13 Jan 2011 13:15:44 +0000 (UTC) (envelope-from faust64@gmail.com) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id 5A2EC8FC1F for ; Thu, 13 Jan 2011 13:15:44 +0000 (UTC) Received: by qwj9 with SMTP id 9so1699148qwj.13 for ; Thu, 13 Jan 2011 05:15:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=gVcCRfBjXJUsDqZMuQYu6dOraUKHK4CPGFVcrNw2QHQ=; b=tD67zloLQaIZiYqfV0Y/QCE46KfbAsD3nJEjlLwXngkIakBOg8zfQmaL2aTHyoKGL5 U9gHzutgYT55RNQLxYFs+hyI3NeNe5SIeph1lOmwj5SwoeJ6rBkMx/UzEPU6OrRIwvuX QDTvF5GVudH8mPxRi+HXGaASYW9/Jzyc5x60A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=RuqXhhvD/YA7qh+2G7m267ZpOGHapOJ/0bJ626bCoDQDZHDaGo5qqoL6zlrs4nTfhX 7Vp69WwwBBkmLsHgeau+pRr6aoUvYSBzJu1cfshn0O0lqKLMKSdarp60WX2Rhk3r1oEe HuR/0EfQTDgnnXkdwR5viLjyYWx820MTkmo+M= Received: by 10.229.75.18 with SMTP id w18mr1971093qcj.95.1294924543280; Thu, 13 Jan 2011 05:15:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.77.215 with HTTP; Thu, 13 Jan 2011 05:15:02 -0800 (PST) In-Reply-To: <4d2ef151.4310df0a.25b7.0199@mx.google.com> References: <4d2ef151.4310df0a.25b7.0199@mx.google.com> From: =?ISO-8859-1?Q?Samuel_Mart=EDn_Moro?= Date: Thu, 13 Jan 2011 14:15:02 +0100 Message-ID: To: four.harrisons@googlemail.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-questions@freebsd.org Subject: Re: problem with shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jan 2011 13:15:44 -0000 ?? 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, 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)