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?
Asked
Active
Viewed 5.3e+01k times
4 Answers
77
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, sudo must be used to manually run it.
- Ensure
/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 - Ensure
rc.localhas a shebang line, which is the default:head -n1 /etc/rc.local #!/bin/sh -e
JW0914
- 107
62
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
foo.sh - Add
#!/bin/shas the first line infoo.sh, executing it viasudo foo.shto check for errors - In
/etc/rc.local, place the full pathname tofoo.sh, prefaced withsh, beforeexit 0:sh '/path/to/your/script/foo.sh' - Verify the first line in
/etc/rc.localis#!/bin/sh -e - Ensure
/etc/rc.localis executable: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
46
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).
rubo77
- 34,024
- 52
- 172
- 299
