Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have some commands that I need to run at startup. I wanted to put them in /etc/rc.local but this doesn't work (bug report).

I've seen a number of different workarounds and I'm sure they all work, but I'm wondering if there is a preferred or even best way to do it? I mean one that might avoid potential complications, or one that may be considered to be best practice in such a situation?

I'm using Linux for business purposes (since Windows died on me yesterday). I'm keen to avoid causing more issues than I am fixing. Thanks in advance.

share|improve this question
    
This one provides all methods available in descriptive way. Which Ubuntu Release are you using. –  atenz Jul 13 '12 at 13:52
    
Obviously, the bestested workaround would be to make the file executable if it isn't. Can you add the output of ls -l /etc/rc.local to the question. –  mikewhatever Jul 13 '12 at 13:57
    
I think the "bug" you reference is nonexistent. Its owned by root, and is +x on 12.04 by default. What're you trying to run in rc.local? –  Thomas W. Jul 13 '12 at 14:15
    
-rwxr-xr-x 1 root root 503 Jul 13 13:22 /etc/rc.local I'm pretty sure my commands are ok. They work fine with a sudo at the command line. –  Simon Roberts Jul 13 '12 at 14:37
    
To test if it gets run, put the following at the start of /etc/rc.local (just below the shebang). exec >/tmp/rc.local-output 2>&1; set -x Then after booting, see if /tmp/rc.local-output exists, and if it does, it should contain all commands run (because of set -x), and all the script's output and error messages. –  geirha Jul 13 '12 at 14:52

2 Answers 2

You should still use /etc/rc.local unless you yourself can confirm that rc.local isnt working.

After consulting with micahg (IRC user) who is on bugsquad and bugcontrol, we've confirmed that /etc/rc.local runs as expected behavior is on 12.04. As the bug you mentioned is "Incomplete", it is likely an edge-case bug and not a bug that is confirmable.


What I would have put on a comment on that bug (but did not after talking with micahg) is this (note that a bunch of it is context-specific for the bug)

rc.local does indeed boot on a clean 12.04 installation. I have confirmed that rc.local does correctly work, after numerous changes to the file and numerous reboots.

I have 30 different commands which activate or deactivate certain services, and run specific services that are not in /etc/init.d/ or upstart. Each and every one of those commands has correctly run (just tested) on a clean 12.04 installation.

Since /etc/rc.local requires superuser to edit, i do not think its getting overwritten or overridden by the desktop, except in certain circumstances where a graphics driver is taking over settings (or a GUI taking over settings for instance for backlight or screen brightness on laptops, which I tend to see happen when a proprietary graphics card's drivers and software are used), in which case /etc/rc.local is most likely being run, but the GUI and relevant software starting afterwards is running additional commands and directives post-rc.local runtime.

This needs additional testing with numerous different command combinations, but expected behaviour of rc.local is indeed occurring on standard 12.04 and 11.04 tests I have run.

share|improve this answer
    
In terms of confirmation, my testing is really limited to whether commands work at the command line (they do) and whether they work when placed in /etc/rc.local (they don't). This was a fresh installation (yesterday) of 12.04. In fact, I installed 11 from CD and accepted the offer to upgrade to 12.04. –  Simon Roberts Jul 13 '12 at 14:40
    
Sorry, I may not have been clear. rc.local does not work (for me). –  Simon Roberts Jul 13 '12 at 14:49
    
As an aside, the "upgrade" might be breaking it. Did you try installing just 12.04 directly? –  Thomas W. Jul 13 '12 at 15:03
    
I didn't, but the suggestion above from geirha seems to suggest that rc.local is being executed. Perhaps it would be more accurate of me then to say that rc.local is being executed, but I am not getting the results that I expect (ifconfig eth0:0 192.168.0.11 netmask 255.255.255.0 broadcast 192.168.0.255), which I appreciate is something very different. –  Simon Roberts Jul 13 '12 at 15:16
    
Indeed, that is something different. What's happening here is that rc.local's commands or something are being overridden post runtime, so perhaps by something like network-manager or some other configuration tool running. –  Thomas W. Jul 13 '12 at 18:29

I realize this an old post....But this is what helped be with automatically mounting windows shares in a ubuntu vitualbox. I added a 10 second pause before my commands.

#!/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 10 
<script to be run>
exit 0
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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