22

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.

juanefren
  • 355

5 Answers5

7

You could add your command to the file /etc/gdm/PostSession/Default before the exit 0 line.

popey
  • 24,549
7

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

Lincity
  • 25,749
dv3500ea
  • 37,734
4

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.

myusuf3
  • 35,659
2

If you do ./app-to-run && sudo shutdown -h now the computer should shut down once app-to-run is done.

Tommy Brunn
  • 10,021
1

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"
samb
  • 1,336