Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-30-2005, 07:35 PM
|
#1
|
LQ Newbie
Registered: Nov 2005
Posts: 17
Rep:
|
How to kill an idle user via the command line?
I'm really sorry to be asking what is surely an easy question, but 1) I have googled for hours and 2) I have searched through old forum posts and 3) I have pulled out a shell programming book and can't figure out how to do this. All I need to do is kill idle users that for some reason persist even though I'm no longer there.
If I run "who," for example, I get the following:
frog pts/1 Nov 30 15:38
turtle pts/2 Nov 30 16:10
turtle pts/3 Nov 30 16:13
turtle pts/4 Nov 30 17:09
frog pts/0 Nov 30 15:38
turtle pts/5 Nov 30 20:02
turtle pts/6 Nov 30 20:27
turtle pts/8 Nov 28 10:09 (remotelogin.zoolab)
"turtle" hasn't been at the zoolab for a day and a half, so why is he still showing up? AND, when I then use "who --all" to get a PID and try (even as root!) to kill it (kill -9 PID#), I get the message "No such process."
What other ways can I kill this idle instance of "turtle." Sometimes there are 30 or more!
Lastly, I know about "idled" but don't really know enough about changing the configuration files to try to get it to do that automatically. I just want to have a simple command line that I can type and kill these idle users whenever I want to.
Thanks very much for any and all help.
|
|
|
11-30-2005, 08:05 PM
|
#2
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Try the "who -q" to determine the users currently logged in.
Also, determine the current processes by user with: ps -u turtle
Then if there are any process by this user, you can kill them by their displayed PID number.
|
|
|
11-30-2005, 08:35 PM
|
#3
|
LQ Newbie
Registered: Nov 2005
Posts: 17
Original Poster
Rep:
|
Can I narrow it down?
Okay, that's a start, but the "who --all" seems to give me more info AND the PIDs. If I do "who -q" it just lists things like "frog turtle turtle turtle frog frog turtle turtle turtle turtle frog" and if I do the "ps -u turtle" then it gives me ALL the PIDs of ALL the turtles. What I need is a way to quickly kill the "turtle" on "pts/8" but NOT the turtle(s) that's logged in and active. I don't want to kill everything with turtle.
If I do "who --all" I get something like this:
LOGIN tty5 Nov 22 15:27 21925 id=5
LOGIN tty6 Nov 19 22:07 1235 id=6
... (more here)
turtle + pts/8 Nov 28 10:09 old 2882 (remotelogin.zoolab)
pts/9 Nov 29 20:59 14807 id=/9 term=0 exit=0
pts/10 Nov 30 15:16 30062 id=/10 term=0 exit=0
...(more here too)
It looks like 2882 is the PID for turtle on + pts/8. But if I try to "kill -9 2882" I get a "Cannot kill 2882...no such process" error.
So what is the syntax to kill JUST that one instance of turtle, the idle one on pts/8? Any ideas?
|
|
|
12-01-2005, 04:46 AM
|
#4
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Does "ps -u turtle" show the processes. I'm wondering if you are looking at processes that were present in the past.
Something else to check is to see if they have cron jobs running.
|
|
|
12-01-2005, 07:06 AM
|
#5
|
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307
Rep:
|
Then just slay the turtle
I dunno if its standard , maybe you have to install it.
|
|
|
12-01-2005, 01:23 PM
|
#6
|
LQ Newbie
Registered: Nov 2005
Posts: 17
Original Poster
Rep:
|
cron jobs?
According to the "who" manpage, "who --all" displays processes.
How do I find the cron jobs and what will this accomplish?
("slay" isn't on my system, by the way. But even if it was, wouldn't that kill ALL instances of turtle? Not just the one on pts/8?)
Thanks...I'm sorry this is still unsolved...
|
|
|
12-01-2005, 05:45 PM
|
#7
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,269
|
It's a bit obscure, but have a look at man wtmp. The "list of who's logged-on" can be fooled.
Use ps -uturtle to see if any processes, particularly bash, still exist which belong to this user-id. If so, you can kill the bash-processes (as root) and this should cause the user to be logged-off. (All of the processes spawned by the session will be direct or indirect descendents of his shell, and should die when it does.)
|
|
|
12-01-2005, 06:01 PM
|
#8
|
LQ Newbie
Registered: Nov 2005
Posts: 17
Original Poster
Rep:
|
Okay...
Thank you, Sundialsvcs, for that info. Interesting. Perhaps this pts/8 "turtle" isn't even there? It's just a phantom that "who" is reporting? That would explain why I'm getting the "can't kill the process, it doesn't exist" error.
Last question for you:
If I have 2 users, frog and turtle, and I _don't_ want to kill all instances of turtle but just a specific one (such as the one on pts/8, not tty3 or pts/1 or pts/2) is there a way to list JUST the bash shells that belong to pts/8? I'm worried that if I kill the wrong bash shell I'll kill the current (non-idle!) turtle instead of the old phantom one.
Lastly, can I clean up the "who" reporting? It doesn't look like I should mess with "wtmp" at all...but if "who" isn't reporting accurate info how do I fix that?
|
|
|
All times are GMT -5. The time now is 08:56 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|