I am trying to get my script to run on startup. I am using Ubuntu Server 16.04.

Here are the exact contents of /etc/r.local.

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.
sleep 1

/home/myusername/myscript.sh 15 &
exit 0

Here's relevant output from /var/log/syslog, when starting up:

rc.local[1157]: /etc/rc.local: 15: /etc/rc.local: /home/myusername/myscript.sh: not found

The script in question has all needed permissions AFAICT.

myusername@myserver:~$ ls -l /home/myusername/myscript.sh
-rwxr-xr-x 1 root root 199 Jan 23 09:19 /myusername/myscript.sh

When manually executing rc.local or my script, it runs fine.

What could be some reasons that rc.local can't access the file on startup?

  • 2
    the sh-bang line of /home/myusername/myscript.sh is suspect; can you post it? – Jeff Schaller Jan 29 '18 at 20:31
  • 6
    Is /home mounted at boot-time when rc.local is executing? – DopeGhoti Jan 29 '18 at 20:34
  • If by sh-bang line you mean the first line, this is it: #!/bin/bash – P. Mensch Jan 30 '18 at 0:07
  • How do I determine when /home is mounted? – P. Mensch Jan 30 '18 at 0:08

If you've got rights to change rc.local you're also able to place your script into /usr/local/bin, or /usr/bin, or even /bin if necessary, which are more likely to be available at boot time than /home, which may be located on a different drive or partition.

Also read more about the usage of rc.local to make sure it's the right place to do what you intend. And be careful of what you do in that script, as it may mess up your boot process.

  • /usr/local/bin did not work. Same problem, rc.local can't find the file. – P. Mensch Jan 30 '18 at 23:06
  • Also, I'm just trying to get a simple script to run on startup and it seemed that using rc.local was the simplest way to do so. I was in fact following the directions of a guide. – P. Mensch Jan 30 '18 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.