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:
- Create a script in the /etc/init.d/ directory
- Make the script executable
$ sudo chmod +x /etc/init.d/myscript.sh
- 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:
10 Comments
→
Hello, thanks for this How-To!
But how can I remove the autostart script if I doesn’t need it anymore?
You can use rcconf – see http://stringofthoughts.wordpress.com/2009/04/16/adding-removing-shell-scripts-ubuntu-810/
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?
Are you running on a shared hosting service? Many of them will kill long-running scripts after a period of time.
No, the computer belongs to me
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.
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.
Prashant, what Linux distribution are you running?
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.
Unfortunately I’m not familiar enough with Ubuntu (Debian) Linux internals to help you on that one, try Google