4

I have some kiosk PCs that pretty much work like the Ubuntu guest session. The kiosk users home has a union filesystem mounted on top of it so the can't change anything but can still save files while working at the machine (and take them with them using a USB key).

Users sometimes leave the stations with private stuff still on the desktop. Because of that I want them logged out after - say - 10 minutes of inactivity (the union file system will be emptied on logout).

Any ideas if there is an existing solution (autolog only logs the user out of active terminal sessions).

  • Read up on these, find which one suits you best. * Ubuntu autolog. manpages.ubuntu.com/manpages/quantal/man8/autolog.8.html * Ubuntu timeouts. /etc/timeouts. manpages.ubuntu.com/manpages/lucid/man5/timeouts.5.html * Ubuntu timeoutd. manpages.ubuntu.com/manpages/intrepid/man8/timeoutd.8.html * With timeoutd, you can also limit what hours a user or tty can log in, set limit on minutes of use, and minutes of idle time. * And a [Google search for you](google.com/… – Bulrush Nov 6 '14 at 18:13
  • 1
    As I mentioned, autolog doesn't work. Neither does timeoutd because both rely on /etc/run/utmp. For utmp the X session is active all the time so it will never be seen as idle. timeouts is just the configuration file of timeoutd. Both work nice for terminal-only applications but not for desktop sessions. – mniess Nov 6 '14 at 18:41
  • So killing the tty is not enough? You need something to kill the Xsession? – Bulrush Nov 6 '14 at 18:47
  • If I do who|grep localhost: every line that contains localhost: I think is an Xwindow. That might help you at least find the Xwindow ttys. – Bulrush Nov 6 '14 at 18:53
  • @Bulrush: I can only repeat what I wrote above. For the reasons stated /var/run/utmp is not suitable to detect if an X user is idle. autolog and timeoutd would work for SSH users, but not for xsession users. – mniess Nov 6 '14 at 18:57
4

Frustrated with autolog, I wrote my own script too. It's on Github.

  • It's general enough for multiple users, on X sessions and TTYs.
  • I have included an Upstart job, assuming that the script is placed at /usr/bin/idlekiller

To set it up:

sudo apt-get install xprintidle
sudo wget https://raw.githubusercontent.com/murukeshm/scratchpad/master/linux/idlekiller/idlekiller.conf -O /etc/init/idlekiller.conf
sudo wget https://raw.githubusercontent.com/murukeshm/scratchpad/master/linux/idlekiller/idlekiller -O /usr/bin/idlekiller
sudo service idlekiller start
  • Way better than my hacked together thing, thanks! – mniess Nov 6 '14 at 23:05
  • @mniess thanks. I wondered whether I should post it, since for the case of a single-user kiosk, your solution is enough. – muru Nov 6 '14 at 23:21
  • I'll use my own thing for sure, but it's always good to have a more general solution. – mniess Nov 7 '14 at 14:42
  • @muru hey what do I have to end and how in your scripts to make it auto logout idle users exactly after 10 mins and warn them after 9 mins but before 1 min of auto logout, that they will be logged out if session stays idle. – Hrish Dec 17 '14 at 11:15
  • 1
    @Rishee I'd changed filenames in the Github code and forgot to update here. Rename idle-killer.sh to idlekiller (no extension) and idle-killer.conf to idlekiller.conf. – muru Dec 18 '14 at 5:52
3

I wrote my own script to do this. There is a tool called xprintidle that gives you the idle time of an xsession. You need to install it first

sudo apt-get install xprintidle

Then create the script, for example in /root/bin/idle_check.sh:

#!/bin/sh

DISPLAY=:0
TIMEOUT=600000 # 10min = 10 * 60 * 1000

if [ $(xprintidle) -gt $TIMEOUT ]; then
    notify-send -t 60000 -i system-shutdown-panel-restart -u critical "WARNING" \
        "This machine looks idle and will be logged out in 60s.\nTo prevent this, move the mouse!"
    sleep 60;
    if [ $(xprintidle) -gt $TIMEOUT ]; then
        pkill -u matthias
    fi
fi

I opened roots crontab to make it check every minute

sudo -i
crontab -e

and have it look like this

SHELL=/bin/bash
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11
*/1 * * * *   /root/bin/check_idle.sh > /dev/null 2>&1

Works like a charm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.