Results 1 to 8 of 8

Thread: Run script as root / sudoers file doesn't work

  1. #1
    Join Date
    Jul 2008
    Beans
    201

    Run script as root / sudoers file doesn't work

    I want to set the brightness of my hp envy 17 with a script (doesn't work in 12.04). The script is called 'bri'

    It containts a line that has to be called as root:

    echo $bri > /sys/class/backlight/intel_backlight/brightness

    The scritpt is owned by root:

    jos@hpux:~/bin$ ls -l bri
    -rwsr-xr-x 1 root root 233 Dec 11 22:11 bri


    The script works when I am root and also when I do 'sudo ./bri ' something
    but when I run it as 'jos' it says 'permission denied'. I tried to change the
    sudoers file, adding permissions for the script (see file below) but it just doenst
    work. What am I doing wrong? ???????



    Jos


    -------------------



    # This file MUST be edited with the 'visudo' command as root.
    #
    # Please consider adding local content in /etc/sudoers.d/ instead of
    # directly modifying this file.
    #
    # See the man page for details on how to write a sudoers file.
    #
    Defaults env_reset
    Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

    # Host alias specification

    # User alias specification

    # Cmnd alias specification

    # User privilege specification
    root ALL=(ALL:ALL) ALL


    # Members of the admin group may gain root privileges
    %admin ALL=(ALL) ALL

    # Allow members of group sudo to execute any command
    %sudo ALL=(ALL:ALL) ALL

    # See sudoers(5) for more information on "#include" directives:

    #includedir /etc/sudoers.d

    jos ALL = (root) NOPASSWD: /home/jos/bin/gpuoff
    jos ALL = (root) NOPASSWD: /home/jos/bin/suspend
    jos ALL = (root) NOPASSWD: /sda10/bin/bri

  2. #2
    Join Date
    Feb 2011
    Location
    Germany
    Beans
    28
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Run script as root / sudoers file doesn't work

    I would do a 'kdesu' / 'gksu' so that you get a grafical ui to enter your pw.
    'kdesu -s' / 'gksu -s' means all following commands will be executed as root.
    Code:
    #!/bin/bash
    kdesu -s
     echo $bri > /sys/class/backlight/intel_backlight/brightness
    exit;
    Last edited by taidoka; May 12th, 2013 at 07:29 PM.

  3. #3
    Join Date
    Feb 2011
    Location
    Germany
    Beans
    28
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Run script as root / sudoers file doesn't work

    Okay I'm too quickly. You want to run it without any pw prompt:

    jos ALL = NOPASSWD: ALL
    jos may execute all Apps without pw.
    or
    %users ALL = NOPASSWD: path/to/script
    Now the group users may execute that script without pw prompt.
    And
    Lowest records have highest privileges. So if there's another record for group %user with ALL = (ALL) ALL then all nopasswd privileges will be removed.

  4. #4
    Join Date
    Sep 2009
    Location
    California U.S.A.
    Beans
    398

    Re: Run script as root / sudoers file doesn't work

    If the path to your script is "/sda10/bin/bri" then how is it that you have a tilde "~" in your previous command (jos@hpux:~/bin$ ls -l bri)? Are you sure your script is at /sda10/ or is it actually at either /home/sda10/bin/ or /root/sda10/bin/ That would make sense as to why your sudoers file is not working correctly. What does "pwd" give you when at ~/bin ?

  5. #5
    Join Date
    Jul 2008
    Beans
    201

    Re: Run script as root / sudoers file doesn't work

    thnx but ~/bin is a link to /sda10/bin .....

  6. #6
    Join Date
    Jul 2008
    Beans
    201

    Re: Run script as root / sudoers file doesn't work

    hi I figured it out: to envoke the script i did

    /sda10/bin/bri

    where I should have done

    sudo /sda10/bin/bri




    (made a not of that)

  7. #7
    Join Date
    Sep 2009
    Location
    California U.S.A.
    Beans
    398

    Re: Run script as root / sudoers file doesn't work

    Oh nice. Glad you worked it out.

  8. #8
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Run script as root / sudoers file doesn't work

    I was just about to post that suggestion, it's a common mistake

    Adding a custom entry like yours to the sudoers file doesn't mean that you don't have to use sudo anymore, it just means that you won't get prompted for a password when you do.
    Cheesemill

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
  •