LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (http://www.linuxquestions.org/questions/debian-26/)
-   -   run this command when the computer shutdown or reboot (http://www.linuxquestions.org/questions/debian-26/run-this-command-when-the-computer-shutdown-or-reboot-683851/)

lindylex 11-16-2008 02:17 PM

run this command when the computer shutdown or reboot
 
I want to run this command when the computer shutdown or reboot.
Code:

alsactl store
Is there a file I can place this into to make it happen? I know how to automate things startings using "update-rc.d" but I don't know how to do it for runlevel 6 and runlevel 0.

Thanks, Lex

repo 11-16-2008 03:32 PM

Put your script in /etc/rc0.d (for halt) and /etc/rc6.d/ for reboot. Make sure script has executable permission

lindylex 11-17-2008 03:56 AM

This is how you should do it.

Code:

su [Enter your root password]
cd /etc/init.d
nano savevolumestate.sh

Inside of savevolumestate.sh place this.

Code:

#!/bin/bash
#LindyLex example to save the audio state.

echo "Saving Audio State."
alsactl store

Code:

chmod a+x /etc/init.d/savevolumestate.sh
Now we tell it to execute when the computer is shutdown or rebooted. Yes that is a period at the end of the command don't forget it.

Code:

update-rc.d savevolumestate.sh start 20 0 6 .
These are the meaning behind the numbers.

- 0 = halt
- 1 = single user
- 2 = CLI, multi-user, no net
- 3 = CLI, multi-user, networked
- 4 = open
- 5 = GUI, multi-user, networked
- 6 = reboot

The "20" you could use this for your script. You can learn more about the meaning of the number after you read about update-rc.d below.

You can learn more by reading the following, execute this in the terminal.

Code:

man update-rc.d

That is it.

Thanks Lindylex

makuyl 11-17-2008 01:29 PM

In a perfect world the above runlevels would apply, but ofcourse Debian has to be different here too :)
Last I looked it was:
- 0 = halt
- 1 = single user
- 2-5 = GUI, multi-user, networked (with runlevel 2 as default in /etc/inittab)
- 6 = reboot

restless 11-25-2008 04:31 PM

i would also change the 20 to a higher value.. maybe something right before or right after gdm or kdm.
the 20 defines in which order the S (start) or (K) kill scripts are started.

when a init enters a specific runlevel, then it will start with the K script with the lowest number, and after it ran all the K scripts, it will start with the S scripts with the lowest number.

To me saving the audio config state doesn't seem that important, and i'd prefer everything else to start first.

other than that, this is the way to go indeed.


All times are GMT -5. The time now is 09:43 PM.