Discussion Locked

Automatic logout of users

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
We have a server running RedHat Linux 6.2. We have 35 users. Can someone tell me how I can have the system automatically log all users off the server at 1:00 AM so that the backup at 2:00 AM will be complete?

6 replies

by fanakart

Just put the following line in root's crontab (crontab -e while logged in as root):
0 1 * * * (/sbin/shutdown -r) > /dev/null 2>&1

This reboot the system at 1:00, thus kicking users out. But this will not prevent them from logging back (if theyare around at 1AM).

You could fiddle with the /etc/nologin file that prevents users logins but this file is erased at boot.

Hope this helps.

Denis

by ronmc

I appreciate your answer. I was looking for something a little less radical than re-booting every night. However, if no one else has a better idea, I might use this.
Thanks

by fanakart

Ron,

Rebooting before a backup is always the safest way to go because it closes every open file.

But if you can't stop some process (database server or some other job that must run at night) then you can do something like this:

# get sorteduser list without root
for user in $(who | awk '$1 != "root" {print $1}' | sort -u); do
# kill nicely every process of every user
kill $(ps -fu denbea|awk 'NR > 1 {print $2}')
sleep 30
# kill every process of every user
kill -9 $(ps -fu denbea|awk 'NR > 1 {print $2}')
done

by ronmc

I think you might be right about the reboot every night. I think I'll try it.
Thank you for your help.

This discussion is closed to new replies.