Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    switch between user account and sudo/root ubuntu 12

    I have abash script in which in midle
    I have to change the etc/hosts and
    /etc//product/conf files.

    How do i switch for a time the context
    of the bash to act as sudo.
    Looks likejust prefixing the commands with
    sudo command goes in a subshell

    and never returns.
    Thank you

  2. #2
    perhaps sudo is not set up right. you should be able to include the command (and possibly the username, if not root) on the command line, after sudo, e.g.:

    sudo whoami
    that should return "root".

    you can list acceptable commands with:

    sudo -l
    (that is a lower case L)

    if you are still having problems, inspect the sudo config file, /etc/sudoers and also any optional config files in /etc/sudoers.d/.

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    For reproduceable configuration file handling, you might want to have a look at augeas, which can be used as-is or from e.g. puppet
    You must always face the curtain with a bow.

  4. $spacer_open
  5. #4
    Thank you
    -l worked

    echo "#added as $(whoami)" >> ~/hosts # as user
    su `whoami` -l "echo "#added" >> /etc/hosts" # in /etc/ as 'root'
    echo "#added as $(whoami)" >> /etc/hosts # as user again

    cat /etc/hosts
    cat ~/hosts

    ls -l ho*
    -rw-rw-r-- 1 marius marius 24 2012-08-19 17:44 hosts
    Last edited by mariuschincisan; 08-19-2012 at 09:42 PM.

Posting Permissions

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