Results 1 to 7 of 7

Thread: How to run a startup script as root/rc.local not running

  1. #1
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Beans
    112
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    How to run a startup script as root/rc.local not running

    Hi,

    I'm using Ubuntu 9.04 on the third partition of my Intel Macbook2,1. I want to run the following command *as root* every time Ubuntu loads:

    xrandr --output LVDS --set BACKLIGHT_CONTROL combination

    This command fixes the backlight brightness controls for Macbooks. It doesn't work if it's not root. If I type 'sudo' plus the command within a terminal, it works perfectly. But I want it to run automatically.

    So I tried this: My /etc/rc.local now reads as follows:

    #!/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.

    xrandr --output LVDS --set BACKLIGHT_CONTROL combination
    firefox

    exit 0

    I put the 'firefox' line in there just to test if this script is running at all. ls -l /etc/rc.local yields:

    -rwxr-xr-x 1 root root 372 2009-05-24 10:20 /etc/rc.local

    Upon booting, the brightness controls are not fixed, and firefox does not load. What's wrong?

    TIA,

    Richard

  2. #2
    Join Date
    Jan 2009
    Beans
    Hidden!

    Re: How to run a startup script as root/rc.local not running

    I don't think that either xrandr or firefox will run from rc.local, because rc.local is not run in an X environment. I recommend that you add the xrandr call to the list of applications that are run when you login. If xrandr needs to be run as root, then you can launch it with gksudo.

  3. #3
    Aearenda's Avatar
    Aearenda is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Beans
    1,109
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to run a startup script as root/rc.local not running

    Brandon is right. In addition, you could set sudo so that your 'sudo xrandr' call does not require a password, using 'sudo visudo' and adding a line like this at the end:
    Code:
    fred ALL=NOPASSWD: /full/path/to/your/command
    Obviously you need to put your username and the proper path to the command in there. If you create a local file to contain the xrandr command, make sure it is only writable by root to avoid creating a security hole.

  4. #4
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Beans
    112
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to run a startup script as root/rc.local not running

    Thank you. Now, how do I make it run on login?

    I have found System->Preferences->Startup Applications and I have added an item in 'Startup Programs' that contains the command:

    gksudo xrandr --output LVDS --set BACKLIGHT_CONTROL combination

    I have also tried 'sudo' instead of 'gksudo', and without the 'sudo', and I even tried putting the command in a script.

    But it doesn't have the desired effect.

    Richard

  5. #5
    Aearenda's Avatar
    Aearenda is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Beans
    1,109
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to run a startup script as root/rc.local not running

    Are you absolutely sure you need it to run as root? I have a call to xrandr in one of my login startup entries, and it works fine. Make sure the no password workaround is in place properly.

    Anyway if you look in ~/.xsession-errors it might give you a clue somewhere. This is where startup program output goes.

  6. #6
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Beans
    112
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to run a startup script as root/rc.local not running

    Hi, Thanks to both who replied.

    I'll post the outcome here for future reference. It turns out that it doesn't need sudo at all, and it seems that sudo/gksudo was what was stopping it from functioning correctly (since it didn't have a password and had no command line interface with which to obtain one). In 9.04, I use System->Preferences->Startup Applications, and simply paste the command with all its switches, and it works.

    Richard

  7. #7
    Aearenda's Avatar
    Aearenda is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Beans
    1,109
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to run a startup script as root/rc.local not running

    That's good news, thanks for telling us the outcome!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •