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

Now, to start the script on startup

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

– 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 start 90 0 6 .

Stop my_script on halt and reboot :

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

That’s all. Have fun!


About synapse
Programming, motorcycles and photography. Want to do more, but only have time for so much!

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

  1. Kumar says:

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

  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 reboot 90 0 6 .
    Does the “reboot” argument exist in this context?
    Shouldn’t the command be like
    # update-rc.d -f 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.

  13. funny videos says:

    There is definately a lot to know about this subject.
    I like all of the points you have made.

  14. Mahjong says:

    Mahjong can be a online game connected with China community
    that is enjoyed, Mahjong some avid gamers, along with items known as tiles.

    Mahjong Merging practices

  15. 半袖T-ブランド tシャツ コピーの通販.弊社プロの誠実、品質が保証しております、ではブランド 服 スーパーコピー通販 、 ブランド 偽物服 通販取扱い店です. シュプリーム コピー Tシャツ_SUPREME スーパーコピー ブランド スリッパサンダルコピー メンズと レディースのブランド 服 スーパーコピー .
    シュプリーム ボックス ロゴ パーカー コピー

  16. Pingback: Attaching some code to session start and end in Linux

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

%d bloggers like this: