Results 1 to 2 of 2

Thread: how to get the user name of the person who called the sudo command?

  1. #1
    Join Date
    Oct 2009
    Location
    Leesville, Louisiana, USA
    Beans
    Hidden!
    Distro
    Ubuntu 11.04 Natty Narwhal

    how to get the user name of the person who called the sudo command?

    I have a script which is called with sudo ./script.sh. script.sh creates files and sets permissions. When I try to get the user name it returns root.

    How can I get the username of the person who called the sudo command so that the user read and write to the files without having to chmod it?

  2. #2
    Join Date
    Nov 2009
    Location
    Australia
    Beans
    57
    Distro
    Ubuntu

    Re: how to get the user name of the person who called the sudo command?

    The environment variable $SUDO_USER holds the name of the account running the sudo command.
    So if you want them to have ownership of a file, you could include in the script something like ..
    Code:
    chown $SUDO_USER.$SUDO_USER filename

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
  •