Killing all active shells without rebooting


View Poll Results: Was this helpful?
No 2 100.00%
Dont know 0 0%
Maybe 0 0%
Yes 0 0%
Voters: 2. This poll is closed

 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Killing all active shells without rebooting
# 1  
Old 06-05-2008
Java 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
# 2  
Old 06-05-2008
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?
# 3  
Old 06-05-2008
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
# 4  
Old 06-05-2008
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Rebooting a career

Apologies if this is not the correct place to post this. I used to have a job supporting several custom applications that ran on Unix platforms. I used shell scripting, sed, awk, and SQL, but all on a pretty basic level. I also performed non-technical tasks like helping with project management,... (4 Replies)
Discussion started by: intranslation
4 Replies

2. Shell Programming and Scripting

How do I calculate total number of active and non active hosts?

#!/bin/bash for digit in $(seq 1 10) do if ping -c1 -w2 192.168.1.$digit &> /dev/null then echo "192.168.1.$digit is UP" else echo "192.168.1.$digit is DOWN" fi done (3 Replies)
Discussion started by: fusetrips
3 Replies

3. AIX

rebooting HMC

Hi, I would like to know wheather rebooting HMC will impact on Management Systems or Lpar inside it is showing? or I have to shutdown LPAR then only reboot HMC. (7 Replies)
Discussion started by: manoj.solaris
7 Replies

4. Solaris

Link based Active Active IPMP

Hi, I need to configure 4 ip address (same subnet and mask) in one ipmp group (two interfaces) in an active active formation (link based). Can some one provide the steps or a tutorial link. Thanks (2 Replies)
Discussion started by: Mack1982
2 Replies

5. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

6. AIX

Question about HACMP for active-active mode

Hi all, I am new to HACMP. So sorry for the newie question. But I did search the forum and it seems that no one asks this before. So if a 2-node cluster runs in active-active mode (and the same application), what is the benefit of using HACMP ? If it runs in active-stanby, it is easy to... (9 Replies)
Discussion started by: qiulang
9 Replies

7. AIX

hmc not rebooting

Anyone faced this? I rebooted the HMC through command line after patch installation (hmcshutdown -t now -r) The strange thing happened was the hmc never rebooted, I was not able to connect it through graphical view or through ssh, but the session through which i issued the command was still... (4 Replies)
Discussion started by: balaji_prk
4 Replies

8. UNIX for Advanced & Expert Users

Active / Non Active users ?

Hey, I have few Questions : 1. How to Check/Find who all are the users accessing the server using their id ? 2. How to Check who is the active user or non active user (whose id exists but the access privileges has been removed) ? I am presently using AIX5.3 as a server. Please suggest... (3 Replies)
Discussion started by: varungupta
3 Replies

9. Shell Programming and Scripting

Killing parent shells from subshells (KSH)

Hi all, I have a shell script which calls other shell scripts, depending on the input. Within a.sh, I have a command which calls b.sh (ie. ksh b.sh) Normally, we use the exit function to terminate a shell. However, if I choose to call exit from b.sh, I will return to the parent shell who... (4 Replies)
Discussion started by: rockysfr
4 Replies

10. UNIX for Dummies Questions & Answers

soft rebooting

When I do a hard reboot, the system recognizes both the ttya and the ttyb, but when I do a hard reboot, it only doesn't recognize the ttyb. Is there a way I can fix this??? Thanks!:confused: (5 Replies)
Discussion started by: nattie_h
5 Replies
Login or Register to Ask a Question