Synapse ↵

logically incoherent… not!

Run a script on Startup / Shutdown in Linux

Hi all, Been a long time! I’ll try to be more regular from now on. Here’s a simple post on how to add a script to your system startup or shutdown

Write a script. Lets call it foo.sh

Now, to start the script on startup -

update-rc.d -f foo.sh start 99 2 3 4 5 .

where
- start is the argument given to the script (start, stop).
- 99 is the start order of the script (1 = first one, 99= last one)
- 2 3 4 5 are the runlevels to start

Dont forget the dot at the end

Start my_script on shutdown and reboot :

# update-rc.d -f foo.sh start 90 0 6 .

Stop my_script on halt and reboot :

# update-rc.d -f foo.sh reboot 90 0 6 .

That’s all. Have fun!

March 24, 2007 - Posted by synapse | Links, Tips and Tricks | | 3 Comments

3 Comments »

  1. “Write a script. Lets call it foo.sh”
    bit more in how to write,may be useful for new commers,like me.
    Thanks

    Comment by Kumar | April 29, 2007 | Reply

  2. Also I think you should explain that this script must be in /etc/init.d for the commands to work, I think. And you have to execute the commands and the placing of the file on /etc/init.d as root.

    Comment by One | December 14, 2007 | Reply

  3. command not found in RHEL 5.3 :(

    Comment by VIKAS | August 17, 2009 | Reply


Leave a comment