PDA

View Full Version : [ubuntu] how to get the user name of the person who called the sudo command?



outleradam
February 13th, 2010, 10:54 PM
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?

wallaroo
February 14th, 2010, 06:50 AM
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 ..

chown $SUDO_USER.$SUDO_USER filename