[CentOS-devel] Environment variable $USER not getting updated on using 'exec sudo command'

Veetil, Vyshnav

Vyshnav.Veetil at harman.com
Wed Apr 11 06:31:02 UTC 2018


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 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.centos.org/pipermail/centos-devel/attachments/20180411/d62eeecd/attachment.html>


More information about the CentOS-devel mailing list