Auto-start a shell script on Ubuntu Server

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/
  3. Make the script start at bootup
    $ sudo update-rc.d 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:

13 thoughts on “Auto-start a shell script on Ubuntu Server”

  1. Hi,

    I want to use 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?

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

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

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

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

  5. 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/
    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.

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

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

  8. @recard the question is more than a year ago … but … you want to use a cron job for this. But I suppose you know it meanwhile 😉

Leave a Reply

Your email address will not be published. Required fields are marked *