I have a script I would like to run when my system starts and have put it in
/etc/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
sudo must be used to manually run it.
/etc/rc.local, and the script it call, is executable:
ls -l /etc/rc.local -rwxr-xr-x 1 root root 419 2010-08-27 11:26 /etc/rc.local
rc.localhas 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, so try this detailed one:
- Save all executing code in a separate text file with an arbitrary name, such as
#!/bin/shas the first line in
foo.sh, executing it via
sudo foo.shto check for errors
/etc/rc.local, place the full pathname to
foo.sh, prefaced with
- Verify the first line in
sudo chown root /etc/rc.local sudo chmod 755 /etc/rc.local
- Verify everything works fine:
sudo /etc/init.d/rc.local start
- Reboot to test
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).