Click to See Complete Forum and Search --> : kill 'em all by user?
posterboy
12-31-2001, 08:29 AM
From time to time, a pal ssh's in here and runs VNC. When he leaves, a number of processes may be left active. A ps -ef shows them by his login name. Is there any way to kill these, in one command, by user name? TIA, Ray
mrBen
12-31-2001, 08:45 AM
Presumably you could right a script that does a ps -aux, greps the resultant output for the username, strips off the useless info and then pipes the results to a kill command.
'cept I don't know how :(. Something along the lines of kill -9 < ps -aux | grep <username> but a little more refined.
Cue TLD
knute
12-31-2001, 09:44 AM
I don't know what shell he uses, but there is a .bash_logout file that will do clean ups when a user logs out.
If it is the same stuff every time, you could put the following into the .bash_logout file
kill -9 $(pidof <filename> )
I actually turned that into a script that I can call to kill processes that die on me. :cool:
Anyway, that should help clean up some of it.
posterboy
12-31-2001, 10:39 AM
Bash. The suggestion about a script set me thinking. How about this one:
kill -9 < ps -ef |awk '/username/ {print $2}'. Maybe? Can't try it, I am the only one in here right now, I don't want to kill myself :)
posterboy
12-31-2001, 12:23 PM
Man, I am surely about to learn something. Did you know that you cannot pipe anything to kill? This is RH6.2 with the stock kill and THIS won't even work:
echo 23657 |kill
I tried awk directly with pipe, nope, then write a diskfile and this: kill <tmpawk NONE of that works? What's happening here?
Ray
Gaccm
12-31-2001, 03:39 PM
try
kill -1 `ps aux|grep username|awk '{print $2}'`
posterboy
12-31-2001, 06:28 PM
No, that's not working for me. Couple of things. That appears to have three 's which isn't right, and it tries to kill itself as we are grepping for the word "username", which is in the calling process. Best I could do with that idea, made kill complain that there was no pid offered. WHAT an I doing wrong, here?
and, thanks for thinking with me on it.
Ray
posterboy
12-31-2001, 08:29 PM
OK, after about 5 hours of puzzling, here's what works:
kill `ps -ef |awk '/snapshot/ {if ($1=="snapshot") print $2}'`
The back tics are imperative. If use kill -9 it will also kill his bash terminal, if he has one. That's for a user named snapshot.
THANKS GUYS!!!!!!!!
Ray