Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to check user activity under Linux (Ubuntu) and after 10 minutes I need to alert the user over email.

By inactivity, I'm referring to CPU usage of the processes that user is running. I tried using "ps -a" to get the user proceses, but I don't know how to check for specific CPU usage

share|improve this question

As your question is not terribly specific I can only guess at what you mean. If by user activity you mean keyboard or mouse, then this can by implemented in a few different ways. In a bash script you can use the command xprintidle (in the standard repositories). Then, if you have the appropriate email set up, you can use e.g. the mail command to send the email.

Alternatively, after detecting the timeout you can also call e.g. a python script and get it to send and email using standard protocols and you favorite email account e.g. gmail. You can read about that e.g. here For sompleteness sake, I have pasted the code example from that page here:

import smtplib

fromaddr = ''
toaddrs  = ''
msg = 'There was a terrible error that occured and I wanted you to know!'

# Credentials (if needed)
username = 'username'
password = 'password'

# The actual mail send
server = smtplib.SMTP('')
server.sendmail(fromaddr, toaddrs, msg)

If you want, you can also keep the entire thing in python. The standard recipe is to use the ctypes module to access libX. I have previously tried implementing one of these recipes and (with the exception of sometime having to replace a few of the lib paths) it works really well. I wont paste those code examples here as they are huge and found on several websites e.g. here, if you want more search for "python x idle time" maybe add ubuntu or linux.

If you have more specific questions to one of these approaches let me know and please also elaborate a little more in your question.

share|improve this answer
I edit the question with more information. I think "xprintidle" can be a good solution, since checking for idle time is more straight forward than checking for CPU usage. But, I need a solution without installing other binaries. – user65405 May 23 '12 at 7:55
In that case how about the Python/ctypes examples I linked to? – TLE May 26 '12 at 14:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.