I'm writing a script (to be run on a multipurpose desktop machine) in which I want to check that there is no user activity.
The non-activity would be defined as:
- Any user using GUI has not been interacting with it (=no mouse or keyboard input) in the past N minutes.
- Any remotely ssh-connected user has not been running any commands or transferring data in the past N minutes.
Where I've gotten so far
ad 1) The only thing that came to my mind is
xprintidle which I used in the past and is a reliable way to check the idle time of the current user but doesn't seem to be usable in the "any current or future logged-in or not user" scenario.
ad 2) I can establish whether there is any open session using:
sudo netstat -tnpa | grep 'ESTABLISHED.*sshd'
This works great but doesn't exactly check for activity and I would like to ignore sessions which are opened but not actively used.
- Could you please suggest a solution for any of the 2 checks?
- Is there any better comprehensive/universal way (e.g. program) to make these checks?