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.

25 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. ufc 162 live says:

    That may be unlawful. Throughout Carmel, a male are unable to put on
    a jacket and pants that definitely not fit. Seems like the fashion law enforcement composed any particular one.
    Inside Carmel that you are additionally a no-no from having ufc 162 live ice cream within the sidewalk.
    Inside Water Area, everyone is not allowed to help swimming in the underwater and also try to eat concurrently.
    They’re also prohibited in order to enjoy pinball upon Sundays, or to promote uncooked fast food sandwich at all. Guys usually are not permitted to proceed nude during area (even should it be not really with regard to small business purposes). Staten Isle features a unusual legislations with regards to backyard repair. You possibly can drinking water the grass that has a hose-pipe if you offer the line with your hands. You can’t don house slippers immediately after
    10: 00pm. There’s no concept on when you find yourself authorized to set your current house shoes returning upon. Perhaps the strangest law can be men and women inside the Express regarding New york can not greet one another by simply “putting someone’s thumbs
    to the nose as well as wiggling your fingertips.
    ” Since i have possess nevertheless to determine anybody meet me personally like this, I will solely believe many people worry the actual abuse for violating this particular legislation.

  11. hello there and thank you for your info – I’ve certainly picked up something new from right here. I did however expertise some technical points using this website, since I experienced to reload the site many times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I’m complaining,
    but sluggish loading instances times will very frequently affect your placement in google and could damage your high quality score if advertising and marketing with Adwords.
    Anyway I am adding this RSS to my email and can look out for a lot more of your
    respective intriguing content. Ensure that you update this again
    soon.

  12. Judson says:

    This design is wicked! You obviously know how to keep a
    reader amused. Between your wit and your videos, I was almost moved to
    start my own blog (well, almost…HaHa!) Great job. I really enjoyed what you had to say,
    and more than that, how you presented it. Too cool!

  13. Paragraph writing is also a fun, if you be familiar with afterward you can write otherwise it is difficult to write.

  14. I know this web page offers quality based articles or reviews and other stuff, is there any other website which gives such information
    in quality?

  15. 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!

  16. Have you read Wicked? Elphaba, who can’t get wet because she’ll melt, uses coconut oil to clean
    herself. I can not imagine slathering myself in coconut oil without imagining what it will be wish to be green.
    And then I burst into song a la Kermit the frog.

  17. Greetings! Very helpful advice within this post!

    It’s the little changes that make the most important changes. Many thanks for sharing!

  18. Wow that was unusual. I just wrote an extremely
    long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing
    all that over again. Anyway, just wanted to say great blog!

  19. 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.

  20. Yup, I understand that there may be a thing
    relation among HostGator along with the Planet but sill
    HostGator have much better support than it..

  21. 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: