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
/usr/local/bin/timekpr &
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…)
* Update:
8-Feb-07 - Found a little math bug - should be fixed now - Barbie sez, “Math is hard!”
4 Responses to “How to Limit Daily Desktop Usage in Ubuntu”
Leave a Reply
You must be logged in to post a comment.











May 11th, 2008 at 3:24 am
Hi, I was looking for a program that does exactly this, and I found something called timeoutd in the repos as well. I was wondering if you have seen this or if you have made any changes to your script since the last update.
May 12th, 2008 at 8:18 am
I had tried timeoutd - one of the problems I found with it is that it doesn’t seem to give any warnings to the desktop when it is about to kill your session. I does fit a real need, it can limit console and shell sessions as well, but it doesn’t really fit my need/want as well.
My script is in active use at our house and has been effective in limiting my teens computer time - that being said, I really need to add a GUI so my wife can control their time allotments and I would like to add some kind of a reward system where Mom can give them extra time to use when they want when they have earned it.
May 27th, 2008 at 5:48 pm
Hi Chris, I loved this script. I’ll put it to use as is to do the same need you mentioned.
But I’ll also try to upgrade it, here is a list of functionalities I believe we can improve:
Must Have
1) Different limitations per day of the week
2) Limit not only by seconds in use, also by specific times of the day, it would be like the user connects but has only 30 seconds to logout (or will be forced logout) if he is not inside a allowed window.
3) Hability to extend the allowed time for the current day if an administrator types in a password and how many time to extend (this would attend your need to give extra time as reward).
Good to Have
Create a control window for the user, so he can check the remaining time at any time and giving him some options, could be the ability to use extra credit (off course reducing the credit from a pool)
4) A graphical interface to administer these options
5) Prevent the user to manually change his control file to “obtain” extra time.
6) A better logout method, something that pushes a logout allowing to save data
7) Support for different languages, best if it is done by plug ins (will allow anyone to create a plug in)
9) Create a .deb package
I personally don’t have much available time, but I also need to ensure proper usage for my teenagers (that is thought) so I will try, first thing first, I will translate the script to Brazilian-Portuguese as I am from Brazil and post it for anyone else to use.
May 29th, 2008 at 10:26 pm
Thanks for the ideas, wagnerpereirasp! I have just started to play with pygtk to see how easy a UI would be and have been thinking about moving the time and limits data to sqlite3.
I currently limit access to the data files by making them only editable but root or an sudoer - there should be a better way. The script has to run as root to force shutdown someone anyone’s session. I wish there was a cleaner way to shutdown gnome-session other than just killing it, but I haven’t found one yet.
A system tray applet that displays the remaining time and can launch the time editor (after a gksudo login) sounds like a great idea!
Translations is also a great idea - I am afraid I’m personally limited to English, so any help is appreciated!