I have a computer that is only used some of the time, and I was was wondering if there was a way to have it turn itself off after a period of inactivity.

Here's the tricky part, if I was just thinking about having it turn itself off when the GUI is idle then I think it would be significantly easier, but I'm trying to make sure I don't cut anyone off who is actively using the machine via SSH as well. The computer in question is Debian 5.0.

Is there a way of detecting if the machine is idle, as in nobody using the GUI and nobody is using the machine via SSH? If an SSH connection is open, but is not actively being used, then the computer should consider that idle.

  • Should this be moved to stackoverflow maybe? – Jeff Welling Aug 3 '11 at 14:44
  • the question isn't particularly programming-ish, and there might be suitable answers which aren't either. – jmtd Aug 3 '11 at 15:26
  • A friend suggested DBUS, but in my brief 5 minutes of googling it didn't look like it would pay any attention to ssh connections, idle or not. I'd would be nice if I was uninformed though.. need to keep looking when I wake up. – Jeff Welling Aug 3 '11 at 15:36
  • 1
    Why would you want to shutdown a Linux computer anyway? :-) – amphetamachine Aug 3 '11 at 21:52
  • @amphetamachine Power saving. Reducing thermal output in a large cluster room. We have two Linux clusters where I work; one 69 machines, another 43: enabling power management has made a measurable difference to the heat of the rooms (which were too hot) and the electricity bill. – jmtd Aug 4 '11 at 14:49
who -q

Will show who, and how many users have an open tty (i.e. at console, via X, ssh, telent) but will not show users connecting via pop, http etc

| improve this answer | |
  • Is there a way of telling of telling what the last command they ran was (PID, to check if it's still running) and when it was executed? Do you think that could be accomplished with some changes to the bash prompt? – Jeff Welling Aug 3 '11 at 15:27
  • You'd need to be a lot more specific about what you mean. What if they started a setsid progam before logging out - would you consider their session still active? What can you not get from the bash history? – symcbean Aug 8 '11 at 20:05

gdm / gnome-power-manager can detect this and suspend the machine appropriately. for GNOME2 Try

gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s --type=int /apps/gnome-power-manager/timeout/sleep_computer_ac 600


gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s --type=int /apps/gnome-power-manager/timeout/sleep_computer_ac 600

as root. You may need to restart gdm for the settings to take effect. (the number is seconds so 600 is 10 minutes).

under GNOME3, there is a similar pair of gsettings keys (the above silently fails).

If you aren't running GNOME, you could inspect the source of gnome-power-manager to figure out how it establishes idle-ness.

| improve this answer | |
  • 1
    gdm / gnome-power-manager can detect idle ssh connections? – Jeff Welling Aug 3 '11 at 15:32
  • idle ones? No. Active ones? I believe so. Your question suggested you didn't want to cut off people using the machine via ssh actively. If you don't want them to suspend even with idle ssh connections, please revise your question. – jmtd Aug 4 '11 at 14:48
  • Actually that sounds like exactly what I want! I'll be checking that out, thank you! Once I've verified that it will work for my purposes I'll choose your answer :) – Jeff Welling Aug 5 '11 at 12:25

Try command xprintidle to get idle time in milliseconds.

| improve this answer | |

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.