small script help

Frank Reppin frank at undermydesk.org
Fri Aug 24 00:51:02 UTC 2012


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


More information about the freebsd-questions mailing list