Script help (sudoed user id)

Khyron320

Senior member
Aug 26, 2002
306
0
0
www.khyrolabs.com
Im trying to get the script to mark who is running the command. But it will always be from a sudo su - USER123 account.

ps -ef |grep grep
will show me the pts session and i can ID the user that way.... but it seems like such a hack is there a value stored somewhere to show what pts is in use and from what user?

There has to be a simpler way.

you cant use
echo $USER when your sudoed it shows the account you promoted too not your own.
 

Khyron320

Senior member
Aug 26, 2002
306
0
0
www.khyrolabs.com
whoami doesnt work. These users do "sudo su -" which loads the env variables of the user you Sudoed too

Also
echo $SUDO_USER does not work in this case.

I came up with this to do it:

REALUSERID=`TTYTEST=$(ps | awk '{print $2}' |tail -1); ps -ef |grep "$TTYTEST$" |awk '{print $1}'`
 

nexus987

Junior Member
Apr 13, 2008
6
0
0
no, not:

whoami

who am i

note the spaces in between "who" "am", and "i". I tried it with sudo and it worked for me...