Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have problem because my friends with I live often forget to shut down our computer. I don't know how solution use to pretend it. There is ubuntu system installed.

I am looking for solution that user will be force to click and confirm (once a hour) that someone uses computer. If he doesn't it computer automatically should do shutdown.

Is there any solution for this problem ?

share|improve this question
up vote 3 down vote accepted

That's a working script of what you want to do:

while true; do
   sleep 59m
   zenity --question --text "Are you using the pc (click anything)?"&
   #the user has 1 minute to answer, otherwise PC will shut down
   sleep 1m
   if kill $zenity_id 2> /dev/null; then 
      #zenity was still running, shutdown the pc
      dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestShutdown

Every once an hour it displays a pop-up asking 'Are you still here?', if the user clicks on something, then it doesn't shutdown for another one hour (in one hour the pop-up is shown again), but if more than 1 minute passes without interaction with the dialog, then the PC automatically shuts down. In order to start this on startup, create a file with the above code and make it executable (right click->properties->permissions->allow executing file as program) and click on the power button to the top right of your screen, select startup applications and add this script.

share|improve this answer

One way to do this is to emulate a press of the power button. Then the following dialog will pop up, and shut down the computer after 60 seconds. enter image description here

To do this, use acpi_fakekey 116 which will "press" the shutdown button (number 116). (At least 116 is my shutdown button. If it fails on your machine,try installing evtest and run it while you press the button)

To automate this every hour, add it to roots crontab like this:

sudo crontab -e and add the following line:

0 * * * * /usr/bin/acpi_fakekey 116

This will press the button at the 0th minute of every hour of every day of every week of every month.

share|improve this answer
Thanks, your advice is helpful, but realized that on this computer lubuntu is installed and it doesn't work the same like in ubuntu because I see new frame with options but there is not automatic time to shutdown. – greg May 1 '12 at 17:41

You could write a simple script using the command shutdown 0 after a prompt.

I should add you can use the sleep command in a loop to realize the waiting.

share|improve this answer

It seems tedious to make someone click a button every specified interval.

You could let gnome-screensaver work for you and check how long it's been running.

In a script, you could do something like the following:


pidof X || exit #not running X!

export DISPLAY=":0" # use current display
DURATION="`gnome-screensaver-command -t | awk '{print $7}'`"

if [ $DURATION -gt 3600 ]; then #idle for an hour
  shutdown -h now

This is a VERY basic example that anyone could expand on. Place it in a cron job or run it in a daemon mode with while/sleep calls.

I would not use it exactly as-is, but just to illustrate a method. This makes the assumption we're using gnome-screensaver. xscreensaver has similar calls.

share|improve this answer

Your Answer


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

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