Hi Dan,

I notice that piping it through wc and doing the "-eq 0" is not neccessary, as grep 
will return
"false" if it can't match the pattern. "-eq 0" is much more friendly, of course :-)

I like your psg alias i think i'll use it! I"ve noticed that grep will often not catch 
it's own
process the first time you filter a ps list but that it will the second, third, etc 
time. 

Cheers,
j


--- Dan Woods <[EMAIL PROTECTED]> wrote:
> 
> Karl Cunningham wrote:
> > 
> > I'm writing a shell script that will have problems if another instance of
> > itself is running, and I'd like to be able to trap that the user has
> > started multiple instances.  I've tried
> > 
> > cnt=`ps ax | grep -c xyz`
> > 
> > where xyz is the name of the script.  It returns 3 when there is only one
> > instance running.  I think I understand why it's 3 (one for the script
> > itself, one for it running ps and one for it running grep?).  Will this
> > always work?  Is there a better way?
> 
> This works from command line...
> 
>    # if [ `ps -efw | grep -v grep | grep rerf |wc -l` -eq 0 ] ; then
> echo 'yes' ; else echo 'no' ; fi
> 
> In a shell script, make it more readable...
> if [ `ps -efw | grep -v grep | grep rerf |wc -l` -eq 0 ]
> then
>    echo 'yes'
>    # more statements here, etc.
> else
>    echo 'no'
> fi 
> 
> -----
> Also, analias command that I use *often* is
>     # alias psg
>     alias psg='ps -efw | grep -v grep | grep'
> 
> This avoids seeing the 'grep' that is forked off by your request.
> 
> Thanks...Dan
> 


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Reply via email to