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

Logoff users 1

Status
Not open for further replies.

malladisk

Programmer
Jun 14, 2001
69
US
Hi, if I'm an administrator (root), how can I logoff all the users on my machine?
Thanks,
Sashi
 
wall"Bye Suckers"|sleep 2 |init 1
 
ha ha, very funny, but can someone please give me a serious answer?
 
Changing your runlevel to 1 (single user mode) with [tt]init 1[/tt] would only allow root to login. //Daniel
 
sco21 was serious.

Wall "Bye suckers" sends a broadcast message to all logged on users. You might want to use:

wall "You are now being logged off. Bye"

This might be better.

wall "You will be logged off in 60 seconds." | sleep 60 | /sbin/init 1

Rob
 
root vc/1 Feb 15 10:18 14:15 1813
mina pts/0 Feb 15 10:19 02:11 1994
paul pts/1 Feb 15 10:45 01:00 2156
kid pts/2 Feb 15 11:06 03:34 2311
sed pts/3 Feb 15 11:06 02:56 2345
bla pts/5 Feb 15 12:00 . 2773
bla pts/6 Feb 15 14:32 00:34 3685
bla pts/7 Feb 15 18:33 ? 4901

who -u -p >/tmp/temp.log

grep pts /tmp/temp.log|awk -F" " '{print $4}'>/tmp/temp0.log

for i in `cat /tmp/temp0.log`

do

kill -9 $i

done


It might work too.
 
Best command to use is "shutdown"....

Check the man page for it. It will warn all users that the system is going down at a particular time or in a particular interval. It will stop anyone else logging in during that time then kick the users off at the appropriate moment. Without using the -r option (reboot) or -h (halt) it will change the system to run level 1 at the given time.

So:

shutdown 22:30 "Please log off for system maintenence"

will have everyone see:




Broadcast message from root (pts/0) (Sat Feb 15 22:05:00 2003):

Please log off for system maintenence
The system is going DOWN to maintenance mode in 25 minutes!





and there will be successive messages during that period.
 
Nah.
wall "Bye Suckers" | sleep 2 | init 1
is the simplest solution.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top