When I shut down my computer I want to show some pending tasks that I have to do before leaving the office.

I have a local application to manage those tasks, so basically I just want to run a command, and shut down after I kill the app that was executed.

I have already tried with these options:


This works only when I select the LogOut option instead Shutdown.


Execute a script after X is killed.


This looks like it does nothing.

./app-to-run && sudo shutdown -h now

I don't like this for two reasons: it prompts for the sudo password, and I can't use my laptop shutdown button.

I am using Ubuntu 10.04.

  • Is it really when you shut down, or do you mean when you log out of the GUI? – David Z Aug 11 '10 at 1:41
  • Did any of the answers work for you? If so, will you "accept" one? – Adam Monsen Mar 3 '11 at 17:23
  • No one worked, I think the way to go is modifying the "Shut Down Computer" windows, but that would involve to recompile Gnome I think. I looked for changing the behavior of SHutDown button, but didn't find the way to run my app. – juanefren Mar 3 '11 at 17:58

You could make an init script in /etc/init.d/ and then configure on which runlevel you want it with chkconfig. I never did what you want, but I would start on this route.

  • /etc/rc0.d/K01mycustomscript might need to be /etc/rc0.d/S01mycustomscript
  • make sure it is executable (chmod 755 /etc/rc0.d/K01mycustomscript or chmod 755 /etc/rc0.d/S01mycustomscript)
  • try some logging: add the line logger 'mycustomscript START' to the beginning of your script, and logger 'mycustomscript END' to the end, shutdown, then look for your log messages in /var/log/messages
  • note that the convention is instead to create a start/stop script in /etc/init.d/, then create symlinks to that script from the appropriate /etc/rc*.d directories, or to use a tool like chkconfig or update-rc.d to maintain the symlinks (see "Init" wikipedia page)
  • see this similar question

Check out /etc/rc0.d/README - it says

The scripts in this directory are executed once when entering
runlevel 0.

The scripts are all symbolic links whose targets are located in
/etc/init.d/ .

Generally it is not necessary to alter the scripts in this directory.
Their purpose is to stop all services and to make the system ready
for shutdown.

You will need to create a script in /etc/init.d and then symlink them to /etc/rc0.d/ to get scripts to run at shutdown.

  • And what's it say? Can you please expand your answer to include the most important information there? Your post is currently flagged as "low quality". Thanks! – slhck Jul 17 '12 at 3:00
  • Put your executable script somewhere—/etc/init.d is recommended.
  • Make a symbolic link from this place from /etc/rc0.d, starting with S (to start this script when getting to runlevel 0.
  • I assume that the machine will wait for this script to terminate before shutting down, though I have never tested this.

the /etc/gdm/PostSession/Default way works:

you have to "fix" the gdm (or mdm in my case) upstart skript:


line15: stop on runlevel [016]


stop on starting rc runlevel [016]

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.