Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that I would like to run when my system starts. I have put it on "rc.local", but it doesn't work. How can I enable it to run on startup?

share|improve this question
Where is the xsetwacom command? /etc/rc.local is executed with a very simple PATH at startup. It probably differs from the PATH you have logged in at the terminal. In the terminal, type: type -p xsetwacom then replace the "xsetwacom" command in /etc/rc.local with the full path as returned by the "type -p". Do you have to do any manual initializations before xsetwacom works for you? – waltinator Sep 28 '11 at 22:09
Using systemd as startup manager make sure the rc.local compatibility is running: systemctl status rc-local.service – rubo77 Apr 21 at 8:09
up vote 20 down vote accepted

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, you need use sudo to manually run it.)

Make sure /etc/rc.local is executable and that the script it calls is also executable.

$ ls -l /etc/rc.local
-rwxr-xr-x 1 root root 419 2010-08-27 11:26 /etc/rc.local

Make sure rc.local has a shebang line (which is the default):

$ head -n1 /etc/rc.local
#!/bin/sh -e
share|improve this answer
Yes, I can run the script manually. How can I make sure /etc/rc.local is executable? What do I have to type? Is it "$ ls -l /etc/rc.local -rwxr-xr-x 1"? Thanks! – pedroo Oct 28 '10 at 8:47
@pedroo: I've copied exactly what I see in my terminal (so you see the prompt, input, and output all above). The command is "ls -l /etc/rc.local" and if it's executable, it will have those Xs in the output. – Roger Pate Oct 28 '10 at 8:50
I've tried the "ls -l /etc/rc.local" and it is executable, but I cannot make it run on startup... Any idea? – pedroo Oct 28 '10 at 23:49
@pedroo: What does this script do? Does it write to any log files that you need to check? (I think it's time to update the question with more details.) – Roger Pate Oct 28 '10 at 23:51
@pedroo: That needs the X server running, which doesn't happen when rc.local executes. Running it from rc.local will just make it exit without doing anything (though I hope it puts a message in syslog or elsewhere). You need to put the xsetwacom commands in ~/.xinitrc or /etc/X/xinit/xinitrc instead. – Roger Pate Oct 29 '10 at 0:07

In my case none of the instructions were a perfect solution. If you were as unlucky as me, try this detailed one

  1. Put all your executing code in a separate text file with an arbitrary name such as and save it in an arbitrary place.
  2. Add


    as first line of your code.

  3. Try executing your by


    to check there are no errors at all.

  4. Provide your /etc/rc.local script with full path and name of your created script after the sh command

    sh '/path/to/your/script/'
  5. Remember to put the above line before the last line of code

    exit 0

    at the end of the /etc/rc.local script.

  6. Check first line of /etc/rc.local to be

    #!/bin/sh -e
  7. Make your /etc/rc.local executable in case it is not already executable by

    sudo chown root /etc/rc.local
    sudo chmod 755 /etc/rc.local
  8. Check everything works fine by executing

    sudo /etc/init.d/rc.local start
  9. Test restart your system.
share|improve this answer
Step #8 was the key, verifying that the script will run under the startup environment. In my case I need to give the full path to the command. – Peter Gluck Jul 19 '15 at 2:22
Prefect and step to step greats, it's works on centos but sudo /etc/rc.local start first run. – Mahdi Parsa Oct 28 '15 at 11:35

2 suggestions.

  1. Ensure that the target script file is also marked executable.
  2. 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 :)

share|improve this answer
rc.local is run as root, so no password is necessary. – enzotib Jun 29 '11 at 21:22

On newer Ubuntu versions systemd is used and /ect/rc.local is not loaded always by default.

Check if the Compatibility service is loaded with

systemctl status rc-local.service

If it contians active (exited) your setting seems fine and you could have another error in your /ect/rc.local file (this could be a command that fails for example)

share|improve this answer

protected by Community Jul 16 '14 at 16:43

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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