Take the 2-minute tour ×


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.


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.

share|improve this question
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
add comment

4 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
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
add comment
  • /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
share|improve this answer
add comment
  • 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.
share|improve this answer
add comment

Your Answer


