Linux – Execute script before shutting down in Ubuntu

gnomelinuxshutdownUbuntuubuntu-10.04

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:

/etc/gdm/PostSession/Default

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

/etc/rc0.d/K01mycustomscript

Execute a script after X is killed.

$HOME/.bash_logout

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.

Best Answer

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.

Related Question