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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

kill command 1

Status
Not open for further replies.

alfred0

Technical User
Apr 5, 2004
7
PR
AIXPERT/S,

CAN I "kill" ALL USERS ONLY? NOT THE PROCESSES?

I NEED TO KILL ALL USERS BEFORE BACKING UP THE SYSTEM.

THANK YOU.
 
Perhaps you could use something like:

for i in `ps -ef |grep -v root |awk '{print $2}'`
do
kill $i
done

This would kill any none root process running on the system. You could exclude other processes or users by added extra grep -v statements.

If you just wanted to kill all processes running due to users being logged in you could add a "grep tty"
 
Also consider fuser -k
see man page...


and if you kill all users...remember the nologin or they will just log right back in.

If the /etc/nologin file exists, the system prevents the user from
logging in and displays the contents of the /etc/nologin file. The
system does allow the root user to log in if this file exists. The
/etc/nologin file is removed when you reboot the system.
 
You could also use finger to get a list of users. This is a (non-AIX, but it should work) script I use to kill off Oracle users and their processes after two hours inactivity, if more than 40 users are logged in. I run it every hour 8:00 am - 5:00 pm:

USERS=`finger | wc -l`
if [ $USERS -gt 40 ]
then
rm users 2>/dev/null
finger -i > times
grep hours times > times1
cat times1 | tr -s ' ' ' ' | cut -f1 -d' ' > times2
for i in `cat times2`
do
ps -ef |grep $i | grep -v root| tr -s ' ' ' ' | cut -f4 -d' ' >> users
done
cat users | while read number
do
kill $number 2>/dev/null
done
else
exit
fi

None too elegant, but effective nonetheless. Hope this helps or gives some idea how to proceed in your circumstance.
 
Ken,

Have you thought about posting this in the Unix scripting forum?
 
bi - good thought. I'll do it on Monday (strange how many times on hears that phrase isn't it?)

But I will - promise! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top