Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a script to kill users

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
Does anyone have a script which will kill all users on a AIX server ?
NB: It must not kill any system or root processes.
 
Never put a kill command in a script.....
 
Tison,

Something like this little for loop would suffiice:

for user in `who -u |egrep -v root |awk '{print $7}'
do
kill $user
done

This is a simple script which kill each users parent process i.e. login PID. The egrep -v means ignore the root user logins and print $7 prints out, as input the PID of user login.

Cheers

PSD
HACMP Specialist
 
# kill -9 `ps -ef | awk '$1=="chavez" {print $2}'`


(blow away all user chavez's processes)
 
I agree that putting a kill command in a script can be dangerous, so use caution with it.

We would typically have 400 to 500 users logged in, each with two processes running, as they attached to the application. After "wall"ing to users to log off, then "echo"ing a statement into /etc/nologin to prevent further logins from occurring, you can use a command line entry if the users have a process that is common. For example, if they all attach to an application called APP1, but you don't want to kill anything that is being run by root or perhaps an APP1 admin ID, you can do something like:

FIRST TIME AROUND DO THIS TO BE ABSOLUTELY SURE OF WHAT YOU ARE GOING TO KILL:

ps -ef|grep APP1|grep -vE "root|APP1adm"

Then check those processes listed to be sure of what the ps -ef sees.


When you are sure of what will be killed:

for x in `ps -ef|grep APP1|grep -vE "root|APP1adm"|awk '{print $2}'`
do
kill $x
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top