Results 1 to 5 of 5

Thread: Running a script with mixed privilages

  1. #1
    Join Date
    Oct 2013
    Beans
    57

    Running a script with mixed privilages

    Trying to automate the install of a tuner card driver,.... the problem is some of the script is run as root,.. some as user.

    How can I run the different parts of the build process within the script as root, without changing sudo stuff and affecting all other 'make' or 'modprobe' executions on my system.

    This is the list of commands I run,.. I appreciate I can drop the sudo if I run the set of commands within a script as root,.. but that defeats what I want to do as some of the script needs to run as user,. and not root.

    ------------------------------------------------------------
    ​ sudo rm -r -f /lib/modules/$(uname -r)/kernel/drivers/media
    cd ~/Downloads/tbs-linux-drivers_v140113/linux-tbs-drivers
    sudo make clean
    sudo make distclean
    sudo ./v4l/tbs-x86_64.sh
    make -j5
    sudo make install
    sudo modprobe -v tbs62x0fe
    -------------------------------------------------------------

    Hope that makes sense,.. and some out there has some ideas for me that escape my limited knowledge..

    many thanks

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Running a script with mixed privilages

    sudo before a command affects only that one command whether you do it manually or inside a script, so I don't quite understand what do you mean.

    Your script would look like (with my comments in red)
    Code:
    #!/bin/sh
    sudo rm -r -f /lib/modules/$(uname -r)/kernel/drivers/media # I suppose you know what you're doing
    cd ~/Downloads/tbs-linux-drivers_v140113/linux-tbs-drivers
    make clean  # no need to be root for this
    make distclean  # neither for this one
    ./v4l/tbs-x86_64  # nor for this one
    make -j5
    sudo make install
    sudo modprobe -v tbs62x0fe
    You run this script as normal user. When executing the first command that is prefixed with sudo it will ask your for password. Then each further command in the script prefixed with sudo will be executed with root privileges.

  3. #3
    Join Date
    Oct 2013
    Beans
    57

    Re: Running a script with mixed privilages

    That's great,.. I was not aware that running sudo within a script worked as though one was typing in at the command line,.. ( I assumed it would prompt for the password at each sudo command ).
    Many Thanks

  4. #4
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Running a script with mixed privilages

    Quote Originally Posted by diyhouse View Post
    That's great,.. I was not aware that running sudo within a script worked as though one was typing in at the command line,.. ( I assumed it would prompt for the password at each sudo command ).
    Many Thanks
    The default timeout is 15 minutes per tty. You can change that, if needed.

  5. #5
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,791

    Re: Running a script with mixed privilages

    Howdy,

    The reason why these things are usually not scripted, is because invariably, something will go wrong, requiring human intervention somewhere along the line. So your script requires error handling after *every* step to make it robust.

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
  •