Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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 = '[email protected]'
toaddrs  = '[email protected]'
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('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

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

 
discard

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