View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Debian This forum is for the discussion of Debian Linux.


  Search this Thread
Old 11-16-2008, 03:17 PM   #1
Registered: Mar 2007
Posts: 170

Rep: Reputation: 17
run this command when the computer shutdown or reboot

I want to run this command when the computer shutdown or reboot.
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
Old 11-16-2008, 04:32 PM   #2
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Linux Mint
Posts: 8,516

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Put your script in /etc/rc0.d (for halt) and /etc/rc6.d/ for reboot. Make sure script has executable permission
Old 11-17-2008, 04:56 AM   #3
Registered: Mar 2007
Posts: 170

Original Poster
Rep: Reputation: 17
This is how you should do it.

su [Enter your root password]
cd /etc/init.d
Inside of place this.

#LindyLex example to save the audio state.

echo "Saving Audio State."
alsactl store
chmod a+x /etc/init.d/
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.

update-rc.d 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.

man update-rc.d

That is it.

Thanks Lindylex
Old 11-17-2008, 02:29 PM   #4
Senior Member
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 53
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
Old 11-25-2008, 05:31 PM   #5
Registered: Feb 2003
Location: Belgium
Distribution: Debian
Posts: 166

Rep: Reputation: 31
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run script on shutdown or reboot VeeDubbs Linux - Server 1 10-23-2008 02:34 PM
Unable to run reboot command??? ajeetraina Linux - Newbie 3 06-05-2008 07:37 PM
Scripts under rc0.d and rc6.d do not seem to run during shutdown.reboot oferu Linux - Newbie 4 03-26-2008 11:34 AM
Computer freezes when I shutdown/reboot from X session scheidel21 Linux - General 2 06-03-2007 08:16 PM
Run command on forced shutdown LinuxBlackBox Linux - Software 3 10-10-2006 08:50 PM

All times are GMT -5. The time now is 08:54 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration