Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

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

share|improve this answer
    
If I go to "Log Out" option it executes fine, But If I press shutdown appear almost instantaneous ubuntu purple logout screen and executes the script (in the screen where appears ubuntu logo with 5 little balls). (tested with sleep 20). –  juanefren Aug 5 '10 at 16:33
    
The "Are you sure you want to shutdown" dialog is located here: /usr/lib/indicator-session/gtk-logout-helper and a part of the indicator-session package witch is written in C/C++ so its pretty hard to edit. You might have more luck asking at some gnome-guru mailinglist ;) –  Source Lab Aug 10 '10 at 18:21

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.

share|improve this answer
    
Since he probably doesn't want the script to run every time, he logs out of bash (i.e. every time he closes a terminal window), I don't think it's a good idea to write the command into .bash_logout. However writing it into PostSession/Default looks like a good idea to me. –  sepp2k Aug 5 '10 at 16:04
    
Already have this file, but looks like it is not working (I put sleep 20 and it didn't wait to shutdown.) –  juanefren Aug 5 '10 at 16:31
    
.bash_logout will not run when you close a terminal, it will only run when you log out from a terminal-login-session (ie. if you logout a real TTY) and not when you logout of gnome. –  Source Lab Aug 10 '10 at 18:24
    
Why would this be a question for superuser? If the question is about Ubuntu it's on topic. –  N.N. Aug 12 '11 at 9:52

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

share|improve this answer
    
From his description it sounds likes he wants to invoke a graphical app, so it needs access to the xserver. In this case using init-scripts does not work. –  sepp2k Aug 5 '10 at 16:05
1  
Yeah... as @sepp2k says, script is running outside xserver :( –  juanefren Aug 5 '10 at 16:36

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

share|improve this answer
1  
This would be a very crude shutdown. You rather want to call the desktop shutdown script instead. –  txwikinger Aug 5 '10 at 15:45
    
The sudo might ask the user to type the password in case app-to-run is long enough... So it'll never shutdown. –  samb Sep 7 '12 at 15:12

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"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.