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

Re: [K12OSN] Help killing users



David Trask wrote:
> 
> k12osn redhat com writes:
> >I always use last instead of who.  In reverse chronological order, last
> >tells you who the last people to log in were (even if they've logged
> >out).  If they're still logged in, last says "still logged in".
> Last works great....now what's the best way to kil them?
> 

Maybe this isn't the BEST way to kill them, but it's almost as brutal as
the shotgun suggestion posted earlier:

kill -9 `ps aux | grep luser | awk '{print $2}'`

In this case, "luser" is supposed to be the username of the offender -
but it'll kill anything that has "luser" in the results of "ps aux."

This is a little better:

kill -9 `ps aux | awk '{print $1 " " $2}' | grep ^luser | awk '{print
$2}'`

This will run ps and print the first two arguments returned (with a
space in between).  Then it greps the output for any line beginning with
"luser", runs it through awk again to grab only the second argument, and
uses the output of that as the argument to "kill -9".

If you want, you could shove all of this into a file and replace "luser"
with $1, which would use the supplied argument as the doomed username:

#!/bin/bash
kill -9 `ps aux | awk '{print $1 " " $2}' | grep ^$1 | awk '{print $2}'`

Just be careful.


-- 
Jim Thomas            Principal Applications Engineer  Bittware, Inc
jthomas bittware com  http://www.bittware.com          (703) 779-7770
The sooner you get behind, the more time you'll have to catch up





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