The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

View Poll Results: Was this helpful?
Yes 0 0%
No 2 100.00%
Maybe 0 0%
Dont know 0 0%
Voters: 2. You may not vote on this poll

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Active / Non Active users ? varungupta UNIX for Advanced & Expert Users 3 05-11-2008 08:00 PM
Killing parent shells from subshells (KSH) rockysfr Shell Programming and Scripting 4 06-28-2007 04:53 PM
AIX timezones - a way around rebooting? willwork4foo AIX 2 10-23-2006 06:10 AM
AIX Constant Rebooting AIXNEWBEE AIX 4 10-30-2005 02:33 PM
soft rebooting nattie_h UNIX for Dummies Questions & Answers 5 03-06-2002 12:15 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-04-2008
Registered User
 

Join Date: Dec 2007
Posts: 2
Post Killing all active shells without rebooting

Hi All,

This may seem to be a very strange request but here is what I am trying to do

1. run a clean up script for my product which will basically remove the directories, entries in the /etc/profile

After that I need to know who all are logged on to the Unix server and log them all off. it so happens that everyone just logs in to our test Unix servers using the root user, so I have to forcibly close their shells and reopen a new shell which(hopefully) will pickup the new and modified profile

Is there a way to do this through a shell script? I am no guru at Unix as you probably can see very clearly...but this piece of code will help me go a long way ahead in the project that I am currently working with

Regards,
Deekshit
Reply With Quote
Forum Sponsor
  #2  
Old 06-05-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
First the good news: if you are root yourself (that is: have the necessary privileges) you can close all the other users shell (including roots sessions) exactly the way you want.

I am no Linux specialist and the output (and the options) of the used commands differ somewhat from UNIX derivate to UNIX derivate so i can tell you only generally how that is done:

Have a look at the "who" command (enter "man who") which will provide you with all the process IDs (PIDs) of the other shell sessions. Use some sort of text filter ("sed" or "awk" usually) to trim that down to a bare list of process IDs and use "kill" on each of these processes to end it. That will effectively log off the user.

Here is a schema of such a script:

Code:
who <some options> | sed <some trimming commands> | while read PID ; do
     kill -9 $PID
done
I hope this helps.

bakunin

PS: may i ask which purpose the poll serves?
Reply With Quote
  #3  
Old 06-05-2008
Registered User
 

Join Date: Dec 2007
Posts: 2
Quote:
PS: may i ask which purpose the poll serves?

i have no idea. it asked me if I wanted a poll and I went ahead with it.

I will try your code and update this thread if it works the way I want it to.

Regards,
Deekshit
Reply With Quote
  #4  
Old 06-05-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
kill -9 is probably (as they say) overkill. The general suggestion would be to just kill or perhaps kill -2 and only if those don't work use kill -9

See also "useless use of kill -9" - Google Search

On Linux who -l lists the PID in the sixth field, so you can do it like this:

Code:
kill `who -l | awk '{ print $6 }'`
I'm wondering if it wouldn't be better if you could simply tell your users to log out and back in with wall in case they're in the middle of something important.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0