When I shut down my computer I want to show some pending tasks that I have to do before leaving the office... I did a local application to manage those tasks, basically I just want to run a command, and shut down after I kill the app executed.
5 Answers
You could add your command to the file /etc/gdm/PostSession/Default before the exit 0 line.
- 24,549
You can do this by creating a script in /etc/rc0.d (for shutdown) and /etc/rc6.d (for reboot). To do this, run:
gksu gedit /etc/rc0.d/K01mycustomscript
Edit your shutdown script in the text editor then run:
sudo chmod +x /etc/rc0.d/K01mycustomscript
And if you want it to run on reboot also then run this:
sudo cp /etc/rc0.d/K01mycustomscript /etc/rc6.d/K01mycustomscript
Source: this forum thread
Sounds like a question for superuser.com to me. Anyway, after some Googling I found How to run a script on logout? which says to add the script to $HOME/.bash_logout.
If that doesn't work, add
$HOME/.bash_logout
to /etc/gdm/PostSession/Default so it executes the logout script properly.
Seeing as before shutdown the user is logged off anyway, this should cover both bases.
- 35,659
If you do ./app-to-run && sudo shutdown -h now the computer should shut down once app-to-run is done.
- 10,021
Almost same answer than Tommy Brunn but without the risk to hang with being asked the root password :
sudo sh -c "./app-to-run; shutdown -h now"
- 1,336