How can I make /etc/rc.local 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
, 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.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, so try this detailed one:
- Save all executing code in a separate text file with an arbitrary name, such as
foo.sh
- Add
#!/bin/sh
as the first line infoo.sh
, executing it viasudo foo.sh
to 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.local
is#!/bin/sh -e
- Ensure
/etc/rc.local
is 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