How to restrict login/usage times

Hello, I have just given a computer to my children which is in their bedroom. One of my concerns is that I don’t want them up all night playing games and surfing the web. How can I set up restrictions associated to their login to only allow them to use the computer at certain times? Say, they’re only allowed to login at 8:00 AM - 9:00 PM. If they’re logged in at 9 PM, I’d also like the ability for the system to lock/log out. Is it possible to set this kind of configuration? I’m using OpenSuse 11 and KDE.


A very easy (and rude to them) one would be to shutdown every five minutes using a crontab entry.

As root in a console do crontab -e and add the following line (or a mutation of that) at the end of the file:

*/5 21-23,0-7 * * *   /sbin/shutdown -hP +1 "Good night!"

Read man crontab for more information.

This will be worth a read if you follow hcvv’s excellent advice:
Cron Tables (Crontab) in Suse / openSUSE [Event Scheduler for 10.x, 11.x]

And if you want to really impress them with your supernatural powers, you could make a recording of your voice, admonishing them about disobeying you and add extra commands to the cron setup so it plays the recording to them, then pauses 10 seconds and then shuts the computer down. If the voice file is myvoice.mp3, you use this version of hcvv’s crontab entry:

*/5 21-23,0-7 * * * mpg123 /path_to/myvoice.mp3; sleep 10; /sbin/shutdown -hP +1 "Good night!"

mpg123 is a command-line audio player installable from standard RPMs using Yast → software management
They’ll be so impressed rotfl!

Hehe, imagination only limits this sort of approach.

When you decide to make a shell script of this, I advise to put the script into /root/bin/ (that is the bin directory in root’s home directory). Do not forget to make it executable for the owner (chmod u+x /root/bin/yourscript) and then call the script from the crontab:

*/5 21-23,0-7 * * *   /root/bin/yourscript

You can then easily change the script without using crontab -e every time. And your script may be as impressive as you like it (you could even check if your own user is active and decide not to shutdown in that case).