time to start learning bash scripting

Longman, Bill yellowdog-general@lists.terrasoftsolutions.com
Tue Aug 26 15:06:01 2003


> > 
> > 	ps caux |grep name_of_program
> > 
> 
> > The name_of_program in question will only ever have one instance in 
> > the ps list, FWIW.
> 
> In this case there will be two.

If you are grepping, yes, you'll always get two lines returned, assuming the
proc you're looking for is also runnning.

Here's the coolest trick up my Bash sleeve:

ps -ef | egrep [a]pache

will return only the running apache PIDs.

> But then I use the following perl code to determine if I need 
<snip>
 Perl code removed because he was trying to learn Bash
</snip>

You can use this kind of construct:

if ps -ef | egrep [a]pache >/dev/null
then
  blah
else
  blah blah
fi

In this example, egrep returns TRUE if it returns any match, FALSE
otherwise.

Bill