Ward William E PHDN wrote:

> -----Original Message-----
> From: Martin Brown [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 12, 2000 4:54 AM
> Subject: Re: Users??
>
> > Last night I used the following to kill a user's processes:
>
> > ps aux | grep username | awk '{print $2}' | xargs kill
>
> > ps aux - get the process list
> > grep username - get lines from the list that contain the username
> >                 (potential problem here if the username has similarities
> >                 to a unix command or directory of program, i.e. 'ash'
> >                 & 'bash', use 'awk' here if such a problem might exist)
> > awk '{print $2}' - get the PID's
> > xargs kill - kill the PID's
>
> > It seemed to work fine, though I certainly want to know if I overlooked
> > something, or there's a better way.
>
> Martin, there is definitely at least a small bug in the script...
> You would need to at least add
>
> grep -v "grep username"
>
> to the string so that one of the processes that you attempt to kill
> isn't the grep of your command!  8o
>
> Of course, this introduces an iterative bug, if the user is greping
> them self at the same time you are....  but that would end when the
> user's shell is killed.
> ct.

how about
ps aux | grep [u]sername | awk '{print $2}' | xargs kill

The brackets on the grep will not allow the grep command itself to be
returned by the grep

Bret


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to