I have some comments about a previously closed topic whose name is the same as above
Omitted from the discussion was the situation with a "sudo command or sudo within a script".
There is an inconsistency between systems. On some systems $LOGNAME is invariant, on others,
on RedHat sudo su and echo $LOGNAME reports the name of the person invoking sudo.
on SUSE, sudo su and echo $LOGNAME reports root. $LOGNAME and $USER report root
Here is a workaround that I discovered and propose:
sudo xxx or sudo su sets up an environment variable SUDO_USER, SUDO_UID,SUDO_GID, and SUDO_COMMAND
It always reports the name of the logon invoking sudo (the caller)
What happens when I sudo su and as root su a third_user?
my system says $LOGNAME and $USER contain the "third_user" id. But
SUDO was invariant
I did not check what happens if the third_user issues as I have liimited my admin logon to one ID.
Please evaluate this posting and re-open that above mentioned topic to see if it is worth merging them together.
[LEFT]I have some comments about a previously closed topic whose name is the same as above
Omitted from the discussion was the situation with a "sudo command or sudo within a script".
There is an inconsistency between systems. On some systems $LOGNAME is invariant, on others,
on RedHat sudo su and echo $LOGNAME reports the name of the person invoking sudo.
on SUSE, sudo su and echo $LOGNAME reports root. $LOGNAME and $USER report root
Here is a workaround that I discovered and propose:
sudo xxx or sudo su sets up an environment variable SUDO_USER, SUDO_UID,SUDO_GID, and SUDO_COMMAND
It always reports the name of the logon invoking sudo (the caller)
What happens when I sudo su and as root su a third_user?
my system says $LOGNAME and $USER contain the "third_user" id. But
SUDO was invariant
I did not check what happens if the third_user issues as I have liimited my admin logon to one ID.
Please evaluate this posting and re-open that above mentioned topic to see if it is worth merging them together.
I have no idea which thread you are referring to, perhaps you can provide a link to this thread?
Anyway, variables like "$LOGNAME" or "$USER" may be common but are in no way standardised (and even less is their content) and hence it is bad practice to rely on any of them. I suggest you use the id command to get the current user ID.
If you want a script you call via sudo to know from which UID it has been called use an argument to do so. Consider this template command:
its call could be turned into:
and subsequently you could inspect the arguments inside /some/command to find out by whom you have been called. Wouldn't that be a more robust way than to rely on some variables which may be defined readonly on one system and different on another?
Its 5pm in Montreal. I will do my due diligence tomorrow AM.
It looks interesting
My original problem was a script that had multiple functions such as
function 1
function 2
function 4.
function ...
The script invokes functions 1,2,3,... and I needed to do sudo for function 4 and continue with function 5..end
I am aware that I cannot sudo a function so, I have been trying other techniques to achieve what needs to be done. This research led to this posting.
the sudo'd function needs to know who invoked sudo in a consistent manner. I found it different between different vendors of Linux (SUSE and RedHat)
Traditionally there was a difference between SysV su and BSD su, only the latter sets USER (and LOGNAME does not exist).
Portable is only su - that is a kind of login shell that sets LOGNAME (if exists) and USER.
GNU/Linux started more BSD-compatible, but later partly changed to Posix that is more similar to SysV.
So yes, it is a mess, and sudo, being a kind of su, makes it even worse.
Hi,
I need some help to setup some environmental variables.
for example...Get A -> userdefined/user input
B -> a number.
c -> system variable...for example $GETCONF PAGE_SIZE
E = do some math using bc
display a message "The value is E"
setup the system/kernel paramter sysctl -p... (3 Replies)
Hi everyone,
I wrote a script that is supposed to be run by cron on a daily basis. It works just fine if I run it manually, but due to a lack of environment variables (which are available during my user session but not when cron runs the script) it keeps failing to run successfully.
Here's the... (2 Replies)
Hi Experts,
Need your help in understanding the commands to setup the environment variables in hp-ux.
Beleive need to use either set,setenv or export.
I am confused between above three options, when to use which option?
On command line, I have tried both set and setenv but couldn't... (1 Reply)
Hi All,
I am using ETL tool Datastage and is installed on Linux environment. Few environment variables are set in datastage. Now my requirement is to use those environment variables in a unix script.
Is there any option I can do it?
Sugeestions from people working on datastage and linux... (1 Reply)
Hi,
I am wondering what is the difference between the USER and LOGNAME environment variables, and under what situations would they be different?
I am using Ubuntu 8.04 32-bit and I do not have 'login' command to test it. (7 Replies)
say i define an environment variable in a particular script (upgrade.sh).
my script is upgarde.sh and it calls another script try.sh. will this environment variable be accessible to try.sh also. if not how to I make environment variables global so that they can be used by any script. (2 Replies)
hi,
I am writing c++ code in unix operating system.In that i need to set the environment variable in unix.
suppose previously i have environment variable like path="something" now i need to change the path value to some othervalue . so that some other program will access that path value... (1 Reply)