19

An elderly relative uses a Ubuntu 18.04 + LXDE desktop, mostly just for internet browsing and to play a few word games. They rarely shut the PC down...last time I checked, it had been turned on for over 15 days.

I administer the system remotely over ssh.

For the occasional time that I need to reboot the system, I'd like some means to determine if my relative is actively using it so that I don't disrupt them. I've done it in the middle of the night sometimes, but they sleep poorly and sometimes get up and play their games then.

Calling them on the phone works, but there are several time zones between us, and sometimes it wakes them up.

If they are playing a game, I can see that in top, but I can't find a way to tell if they are actively using the browser.

Some kind of mouse and/or keyboard activity indicator would be awesome, but I wish to stay away from any kind of keylogger type software. I suspect such a "mouse/keyboard activity detected" thing exists - to put the system to sleep / activate the screensaver** and wake it up if for nothing else - but I can't find it.

** I don't think they actually use a screensaver, that was just an example. I think the power manager just blanks the screen.

Is there a "time since last keyboard/mouse interaction from user" tracked somewhere?

Any solutions need to be do-able over ssh.

5
  • Could you search the browser cache for the most recent file and make a judgment from that?
    – PonJar
    Commented Oct 10, 2021 at 9:16
  • @PonJar that might not cover the game-playing case. Commented Oct 10, 2021 at 12:14
  • This is definitely beside the point, but 15 days isn't necessarily that long. E.g. I'm writing this comment from a KDE desktop that has been continuously up (and logged in) for 48 days and is totally fine. So if you ever want to reboot the computer just because you feel like it's been up too long, it might be a perfectly reasonable solution to wait, and save the reboots for when you need to do major software updates or stuff like that.
    – David Z
    Commented Oct 11, 2021 at 6:57
  • @DavidZ yeah, I know people do different things. I only need to reboot it for kernel updates. The only reason I mentioned it staying on was to reinforce that if I don't reboot the thing, they never will. Commented Oct 11, 2021 at 18:37
  • 10/10 for getting them on a GNU/Linux distro -- it's just so much easier to manage. To reinforce the reboot thing that David Z mentioned, I have my wife run Garuda GNU/Linux on the Dell ultrabook she uses for work and she hasn't had to reboot in months. We don't update it that often because it's not a server and so isn't much of a security risk. I'd say that your relative's machine probably doesn't need much maintenance either for the same reasons -- if it's working, just leave it alone. Commented Oct 12, 2021 at 8:25

4 Answers 4

25

There exists an utility to print the idle time of the X screen:

DISPLAY=":0" xprintidle

It prints the time since last keyboard or mouse input in milliseconds.


Another option would be to pop up a question box:

DISPLAY=":0" zenity --question --text="Organic Marble asks: Are you currently using this computer?" && echo yes

Then if you get no answer within a few minutes, just ctrl-c it out and proceed to reboot.

4
  • 1
    The interactive approach is one I had not thought of! Thanks! But the first one looks perfect. I will need to install the command and test it out. Commented Oct 10, 2021 at 15:09
  • 4
    If you always get small idle times, it may be that they have a jittery optical mouse. Might also explain why the monitor is always on.
    – jpa
    Commented Oct 10, 2021 at 15:15
  • 1
    This looks perfect. I can do expr $(DISPLAY=":0" xprintidle) / 60000 to get idle time in integer minutes. I just need to monitor it for a few hours and make sure that I see it go down before accepting. Commented Oct 10, 2021 at 15:33
  • Works a treat! Thanks for teaching me about xprintidle Commented Oct 10, 2021 at 17:36
8

If the monitor is configured to save energy, you may check it:

xset -display :0 q

Look at last line:

Monitor is Off
3
  • 3
    This looks very promising! I just tried it and got "Monitor is On". I'll keep checking and see if it ever goes off. Commented Oct 9, 2021 at 19:10
  • @OrganicMarble so is it ever off?
    – justhalf
    Commented Oct 10, 2021 at 5:49
  • 2
    @justhalf I've checked it several times over the last day. It has always shown 'on', so this solution may not work in my case. Commented Oct 10, 2021 at 12:13
6

Well... this is only an idea, but if you login via ssh to the same user that your relative is using, set the DISPLAY environment variable to :1 and run xinput test n where n is the number corresponding to the mouse (you can obtain that number with xinput --list, in my case it's 9), then that command will print a line of text (in form like motion a[0]=338 a[1]=889) whenever the mouse is moved. So you can pipe the output from that command to some script that will record time when it last got any input, thus you will know when the mouse has been last moved (of course this has to run constantly in the background to record actual time of last mouse movement).

1
  • If they are watching video there may not be mouse traffic? Keepalives tend to be a keyboard buffer hack?
    – mckenzm
    Commented Oct 10, 2021 at 5:53
0

I think the only way you're going to know for absolutely sure is to "spy" on their screen.

  1. Install x11vnc on their computer with sudo apt-get install x11vnc net-tools

  2. (Optional) Create a shell script on their computer to automate the process of starting the server, so you don't have to remember the syntax every time. Note that the -auth parameter may need to be changed; I only have Fedora to test with right now, and Ubuntu might save the auth file in a different location.

#!/bin/sh
sudo x11vnc -auth /var/run/lxdm/lxdm-\:0.auth -display :0 -rfbport 5900 -localhost
  1. Install your favorite VNC viewer application on your computer.

  2. Set up SSH port tunneling for port 5900 on your computer. Assuming you're using OpenSSH, put the following in your .ssh/config file:

Host theirhostname
    LocalForward 5900 localhost:5900

When you want to actually look at their screen:

  1. SSH into their computer as normal.

  2. Run the shell script (or type out that big sudo x11vnc line).*

  3. Start your VNC viewer application, and direct it to connect to localhost.

Voila, you should be able to see their screen.

*Note: You're going to get several warnings that the VNC server isn't protected by a password. This isn't a security risk, since the VNC server port can only be accessed locally, meaning that any attacker would have to already be logged in. If you're really concerned, though, use x11vnc -storepasswd to create a password file, then add -rfbauth /home/user/.vnc/passwd to the x11vnc command line.

3
  • I am a regular user of VNC, but I need to be able to do this from my phone sometimes using only terminal capabilities. Thanks for a good suggestion that could work for someone else, +1. Commented Oct 10, 2021 at 15:36
  • 1
    @OrganicMarble I routinely use VNC to log in to my computer from my (android) phone, using a SSH app called Termius and a VNC client called VNC Connect. (There are others, of course, those are just the two I happen to use.) Commented Oct 10, 2021 at 15:39
  • 3
    Thanks. I also don't feel comfortable watching their screen without their permission, and if I have to ask for permission, they have to be there... Commented Oct 10, 2021 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .