Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Aug 2012 02:50:49 +0200
From:      Frank Reppin <frank@undermydesk.org>
To:        Jack Stone <jacks@sage-american.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: small script help
Message-ID:  <5036CFE9.1010602@undermydesk.org>
In-Reply-To: <5036C751.20704@sage-american.com>
References:  <5036B542.1040509@sage-american.com> <5036B897.1050101@undermydesk.org> <5036C751.20704@sage-american.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 24.08.2012 02:14, Jack Stone wrote:
> Thanks, I tried that but pgrep only displayed the PIDs. I guess I wasn't
> using proper switches.
Yes - and this should be enough.
If pgrep returns PIDs - then this is the same as 'true' in your
'if' condition - if it returns nothing, the 'else' part is executed:

#!/bin/sh
# * example for Jack with amavisd instead of apache
# * the ^ means 'match from the beginning'
# * so your content for PROCESS_PATTERN would be
#   PROCESS_PATTERN="^/usr/local/sbin/httpd"
#   because ps -ax would show you this in the
#   COMMAND row

PROCESS_PATTERN="^/usr/local/sbin/amavisd"
PGREP="/bin/pgrep"

if ${PGREP} -q -j none -f ^${PROCESS_PATTERN}; then
   echo -e "OK"
else
   echo -e "FAIL"
fi

hth,
Frank Reppin



-- 
43rd Law of Computing:
         Anything that can go wr
fortune: Segmentation violation -- Core dumped



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5036CFE9.1010602>