Re: grepping in ps output

2000-04-30 Thread Chris Frey
On Fri, Apr 28, 2000 at 07:39:37PM -0400, B.C.J.O wrote:
 Evi Nemeth had a good trick for dealing with  that situation using the
 short test notation:
 
 f'rinstance, you want to nuke every process owned by user:
 
 kill -9 `ps aux | grep [u]ser | awk '{print $2}'`
 
 ... where the trick is obviously the square brackets around the first
 letter in the username, testing for the existence of that letter in the
 grep output. This prevents the grep from being killed off before the
 command can complete.

Actually all it does is prevent kill from trying to kill a non-existant
(or entirely new, but that's unlikely) process.  The ps aux pipeline,
including the grep, will have finished before kill -9 starts, since
kill needs the output for its command line args.

Neat trick though.  I'll have to remember that.

- Chris



Re: grepping in ps output

2000-04-30 Thread Larry Morrow
Hi ,

Just use eax with =out the - for linux.

example for named

 ps eax | grep named | sed -e 's/^  *//' -e 's/ .*//'

Larry

At 12:18 AM 4/29/00 +0200, Paul van Empelen wrote:

Hi,

I am working on a bourne script that can restart services if they hang.
If the process does not respond, I want to kill and restart it, but I 
haven't found a good way to locate it's process ID from the ps output. 
And not all processes use a /var/run/file.pid.  With the commands
ps ax | grep process, you sometimes see the 'grep process' in the output. 
That's not what I want.

The following command works pretty well on Solaris. Does anybody know
the Debian equivalent?

PID=`ps $PSOPTION | grep $SERVICE| sed -e 's/^  *//' -e 's/ .*//'`
(where $PSOPTION is -e for Solaris, and probably ax for Linux)

Thanks,

Paul.


--  
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]