[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: shell script problem
On Sun, 25 Oct 1998, Ze'ev Maor wrote:
> On Sun, 25 Oct 1998, Itamar S.-T. wrote:
>
> > #!/bin/sh
> > numps=`ps xa | grep pnserver | wc -l`
> > if test $numps -lt "2"
> > then
> > /usr/local/pnserver/bin/pnserver /usr/local/pnserver/server.cfg
> > fi
>
> Define "won't work", "won't work" as in it doesn't even start, i.e. it's
> not in your path?? Basically this isn't the right way to do this, the
> "grep" process might not even start until the ps has finished, in which
> case you only have 1 line of output from the grep command, while the
> pnserver IS running, and you'll think it isn't (it DOES happen, try
Yes, but the fix for this in his case is:
numps=`ps xa | grep pnserver | grep -v grep | wc -l`
and compare to 1. Yes, I know it's a sin. The lesser sin is to use gawk
instead of grep. Or Perl ;)
> running the ps + grep command from shell many times one after the other
> while the pnserver (or any other program for that matter runs) and you'll
> see that sometimes you get 2 lines of output - i.e. the grep actually
> started running while the ps was running - and sometimes you'll only get
> one, depends on load average/cpu scheduling.)
>
> You should check whether the pnserver, registers itself in /var/run (like
> pppd and other apps do) if so, the script should say:
>
> numps=`cat /var/run/pnserver.pid` # Or something like that.
>
> If not you could try using zap.
Peter