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.shand save it in an arbitrary place.
as first line of your code.
Try executing your
to check there are no errors at all.
/etc/rc.localscript with full path and name of your created script after the
Remember to put the above line before the last line of code and
at the end of the
Check first line of
/etc/rc.localexecutable 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 by restarting 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).