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 root, sudo must be used to manually run it.
Ensure /etc/rc.local, and the script it call, is executable:
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).
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 asroot
,sudo
must be used to manually run it./etc/rc.local
, and the script it call, is executable:rc.local
has a shebang line, which is the default:In my case, none of the instructions were a perfect solution, so try this detailed one:
foo.sh
#!/bin/sh
as the first line infoo.sh
, executing it viasudo foo.sh
to check for errors/etc/rc.local
, place the full pathname tofoo.sh
, prefaced withsh
, beforeexit 0
:/etc/rc.local
is#!/bin/sh -e
/etc/rc.local
is executable: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
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).2 suggestions.
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 :)