Skip to content

Auto-start a shell script on Ubuntu Server

by Jonathon on April 23rd, 2009

Got a shell script that you want automatically run at bootup on Ubuntu Server Edition? Here’s how:

  1. Create a script in the /etc/init.d/ directory
  2. Make the script executable
    $ sudo chmod +x /etc/init.d/myscript.sh
  3. Make the script start at bootup
    $ sudo update-rc.d myscript.sh defaults

Note: the option “defaults” puts a link to start your script in runlevels 2, 3, 4 and 5, and puts a link to stop in runlevels 0, 1 and 6.

Referenced from:

From → Notebook

12 Comments
  1. Hello, thanks for this How-To!

    But how can I remove the autostart script if I doesn’t need it anymore?

  2. Hi,

    I want to use myscript.sh to start an application. after reboot, I found my application was indeed started (it has some log files), but it was somehow killed by the system. Do you know why?

  3. Jonathon permalink

    Are you running on a shared hosting service? Many of them will kill long-running scripts after a period of time.

  4. No, the computer belongs to me

  5. Jonathon permalink

    In that case, I’ll need to know more about your setup. Email me at jhill9693 at gmail dot com if you would like to continue the conversation.

  6. when i fire command sudo update-rc.d myscript.sh defaults
    then display the below error

    update-rc.d: warning: /etc/init.d/test.sh missing LSB information
    update-rc.d: see
    System start/stop links for /etc/init.d/test.sh already exist.

  7. Jonathon permalink

    Prashant, what Linux distribution are you running?

  8. stephen permalink

    I did that on Ubuntu 10.04 and it does not run the script. is there a log somewhere to show swhat is the problem? if I start it manually by executing sudo /etc/init.d/myscript.sh
    it runs fine.
    also there is a file /etc/rc.local by default and I changed the execution bits on that and still it does nothing.
    thanks for looking at this.

  9. Jonathon permalink

    Unfortunately I’m not familiar enough with Ubuntu (Debian) Linux internals to help you on that one, try Google :)

  10. recard permalink

    How can I auto-start a shell script once-per-day (e.g. every day at 10:00 pm) under Ubuntu/Linux Server ?

Trackbacks & Pingbacks

  1. Node.js Dev Environtment » Note

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS