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!

About these ads

About synapse
Synapse is an easy going person who loves technology. He is a Software Engineer working in the field of Medical Electronics. He likes music, movies, motorcycles and has a passion for photography.

16 Responses to Run a script on Startup / Shutdown in Linux

  1. Kumar says:

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

  2. One says:

    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.

  3. VIKAS says:

    command not found in RHEL 5.3 :(

  4. Pingback: ter Smitten's » Using init (bootup & shutdown) scripts in Debian/Ubuntu

  5. ivalo says:

    I was wondering if the last command was incorrect.
    # update-rc.d -f foo.sh reboot 90 0 6 .
    Does the “reboot” argument exist in this context?
    Shouldn’t the command be like
    # update-rc.d -f foo.sh stop 90 0 6 .

  6. Pingback: Power off USB mass storage at computer shut down??

  7. icon-design says:

    Many thanks for an explanation, now I will know.

    By the way, what do you think about this icons site?

  8. Eusebia says:

    Awesome post.

  9. Whether you have had the privilege of seeing some of the world’s most majestic animals up close or simply have appreciated them from afar through books, movies or on television, giant stuffed toys can give you that warm and fuzzy feeling we all hope to find. Make your children more happy by giving quadrilla try me set precio and quadrilla basic set. So, if you are planning to surprise your kid on his or her birthday, do buy some best toys for them online from one of best toys companies like the Fisher Price, Play Tool, Hot Wheels and many more as they sell genuine toys with long lasting effect.

  10. floor grates says:

    When I initially commented I clicked the “Notify me when new comments are added” checkbox and now
    each time a comment is added I get four e-mails with the same comment.
    Is there any way you can remove people from that service?
    Thank you!

  11. I blog quite often and I seriously thank you for
    your content. The article has truly peaked my interest.
    I’m going to take a note of your blog and keep checking for new details about once per week.

    I subscribed to your RSS feed too.

  12. Domy kli says:

    If some one needs expert view about blogging and site-building afterward i recommend him/her to pay a
    visit this web site, Keep up the fastidious work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: