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.

I have a shell script I'd like to run automatically every time I logout, shutdown or reboot.

Does anyone know where can I configure this in Ubuntu 10.10?

share|improve this question
add comment

2 Answers

To execute a script at startup of Ubuntu

  • Edit /etc/rc.local and add your commands.
  • The script must always end with exit 0

To execute a script upon rebooting Ubuntu

  • Put your script in /etc/rc0.d
  • And make it executable (sudo chmod +x script)
  • Note that scripts in this directory are executed in alphabetical order.
  • The name of your script must begin with K99 to run at the right time.

To execute a script at shutdown

  • Put your script in /etc/rc6.d
  • and make it executable (sudo chmod +x script)
  • Note that scripts in this directory are executed in alphabetical order.
  • The name of your script must begin with K99 to run at the right time.

To execute a script on logout

  • man bash has this to say about it: When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists. So you can add script executed during logout to ~/.bash_logout.
  • Do make sure it is executable.
  • You might need to add $HOME/.bash_logout to etc/gdm/PostSession/Default for it to work.
share|improve this answer
    
Using Ubuntu 12.04, and directory /etc/gdm doesn't exist. Where else I can put the script such that it executes on logout as well as shutdown? –  Kush May 12 '12 at 14:22
add comment

It is very simple. Go to "System" and then to "start up applications" (i am not with a english verision - but you wil remark it what i mean). Press on the button "add" and simlply fill the necessary things.

If you want only to run at shutdown: make a script with de shutdown command into it, but before this command line execute your task you want to do. To shutdown / poweroff Ubuntu Linux

sudo halt or sudo shutdown -h now To reboot Ubuntu Linux sudo reboot

Shutdown command can only be executed by the root. Change the shutdown command wrigths, this is the most simply way..

share|improve this answer
    
what about shutdown/reboot tasks? –  Alex Jun 14 '11 at 17:42
add comment

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.