How to Limit Daily Desktop Usage in Ubuntu
I have been looking for a way to limit the amount of time my kids spend on the computer. After toying with a couple of different things like timeoutd and pam_time, I decided to hack together something to meet my needs:
- My kids share a PC with their Mom using fast-user-switching, so I needed it to keep track of multiple sessions.
- I needed different times for different users ( Mom wouldn’t be too thrilled with me forcing her to log off after an hour or two )
- I wanted everyone to get ample warning so they could save their work and logout cleanly.
With those ideas in mind I came up with this:
What timekpr does is watch for instances of the session manager, keep a running tally of the time they are running, and logs kills it when time is up. Several libnotify alerts let the user know when thier time is running out.
It’s pretty rough right now ( just a couple of hours of research and bash hacking ) but it just kicked my son of the PC after his alloted hour and a half, so it’s functional – YMMV – I need to allow for different time limits on the weekends, and it uses a less than elegant method for shutting down gnome-session, so it’s very much a work in progress.
To install it, down load the script, timekpr , and rename it. Copy it someplace useful and make it executable:
mv timekpr.txt timekpr.sh
chmod 755 timekpr.sh
sudo mv timekpr.sh /usr/local/bin
Next make a directory for the time tracking files and limits:
sudo mkdir /var/lib/timekpr
I added a line to /etc/rc.local
to start the script after a re-boot.
to limit someone’s per day usage, just add the number of seconds they will be allowed to a file in /var/lib/timekpr
sudo echo 7200 > /var/lib/timekpr/username
where username is the account you want to time limit.
I hope some parent finds this useful, my kids hate it already! (Heaven forbid they should go outside now and then…)
8-Feb-07 – Found a little math bug – should be fixed now – Barbie sez, “Math is hard!”