I have a script that I would like to run when my system starts. I have put it on "rc.local", but it doesn't work. How can I enable it to run on startup?
Can you run your script manually? If not, it's a problem with that script; otherwise look more at rc.local. (If that script needs to run as root, you need use sudo to manually run it.)
Make sure /etc/rc.local is executable and that the script it calls is also executable.
$ ls -l /etc/rc.local -rwxr-xr-x 1 root root 419 2010-08-27 11:26 /etc/rc.local
Make sure rc.local has a shebang line (which is the default):
$ head -n1 /etc/rc.local #!/bin/sh -e
In my case none of the instructions were a perfect solution. If you were as unlucky as me, try this detailed one
- Put all your executing code in a separate text file with an arbitrary name such as foo.sh and save it in an arbitrary place.
as first line of your code.
Try executing your foo.sh by
to check there are no errors at all.
Provide your /etc/rc.local script with full path and name of your created script after the sh command
Remember to put the above line before the last line of code
at the end of the /etc/rc.local script.
Check first line of /etc/rc.local to be
Make your /etc/rc.local executable in case it is not already executable by
sudo chown root /etc/rc.local sudo chmod 755 /etc/rc.local
Check everything works fine by executing
sudo /etc/init.d/rc.local start
- Test restart your system.
On newer Ubuntu versions
systemd is used and
/etc/rc.local is not loaded always by default.
Check if the Compatibility service is loaded with
systemctl status rc-local.service
If it contains active (exited) your setting seems fine and you could have another error in your
/etc/rc.local file (this could be a command that fails for example).
- Ensure that the target script file is also marked executable.
Is the target script running a sudo command? If so you might want to supply the sudo password to it.
My bad. Just check one then. Thanks for the correction enzotib :)
protected by Community♦ Jul 16 '14 at 16:43
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?