Hi All,
We are facing an issue with exec sudo command which is resulting in an infinite loop.
We have one script in which we are checking if $USER is not equal to root then execute the same script with exec sudo so that it will run with root.
Code snippet:
script1:
if [[ "$USER" != "root" ]]; then
exec sudo $0 $@
fi
If we run the script with some another user say root1 using below
"sudo -u root1 script1" script1 will run in an infinite loop.
In CentOS 7.4 when exec sudo command runs, the value of $USER remains same i.e root1 and again it enters and if block and execute the scipt1 and so on ..
While in case of Centos 7.3 after running exec sudo command value of $USER gets updated to root and it works fine.
Centos 7.4 sudo Version :
Sudo version 1.8.19p2
Centos 7.3 sudo version:
Sudo version 1.8.6p7
We want to know the root cause of this issue and also want to know what has been changed in sudo package regarding this problem.
Please help.
Regards,
Shagun
using 'exec sudo' command env variable $USER not getting updated
Re: using 'exec sudo' command env variable $USER not getting updated
Use sudo -i
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Re: using 'exec sudo' command env variable $USER not getting updated
Thanks for the response.
I run the sudo -i command but it is not working for me because it is asking for a password.
But my question is what has been changed in CentOS 7.4 for sudo package So, the same command which was running in 7.3 is not running in 7.4?
Regards,
Shagun
I run the sudo -i command but it is not working for me because it is asking for a password.
But my question is what has been changed in CentOS 7.4 for sudo package So, the same command which was running in 7.3 is not running in 7.4?
Regards,
Shagun
-
- Posts: 519
- Joined: 2012/06/26 14:20:47
Re: using 'exec sudo' command env variable $USER not getting updated
I would say test $EUID rather than $USER.
If you want to know about changes to versions of sudo look at the project page:
https://www.sudo.ws/
If you want to know about changes to versions of sudo look at the project page:
https://www.sudo.ws/