[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Users??



At 01:53 2000-07-12 -0700, Martin Brown wrote:
>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)

How about this:

ps aux | grep "^username\b" | awk '{print $2}' | xargs kill

That grep option will catch the username only if it exactly matches the
first column of output from "ps aux". The caret "^" specifies that the
string must be at the beginning of the line. The "\b" specifies that the
string is a word (is followed by non-word characters like whitespace or
end-of-line).


 Tony
 --
 Anthony E. Greene <agreene pobox com>
 PGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26  C484 A42A 60DD 6C94 239D
 Linux: The choice of a GNU Generation.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]