<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 11/04/18 07:31, Veetil, Vyshnav
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:ee71743281c74fc8a57df81712baf9b1@HIBDWSMB08.ad.harman.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:10.5pt;font-family:"Arial",sans-serif;color:#333333;background:white">Hi
All, </span><span
style="font-size:10.5pt;font-family:"Arial",sans-serif;color:#333333"><br>
<span style="background:white">We are facing an issue with
exec sudo command which is resulting in an infinite loop. </span><br>
<span style="background:white">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. </span><br>
<span style="background:white">Code snippet: </span><br>
<span style="background:white">script1: </span><br>
<br>
<span style="background:white">if [[ "$USER" != "root" ]];
then </span><br>
<span style="background:white"> exec sudo $0 $@ </span><br>
<span style="background:white">fi </span><br>
<span style="background:white">If we run the script with
some another user say root1 using below </span><br>
<span style="background:white">"sudo -u root1 script1"
script1 will run in infinite loop. </span><br>
<span style="background:white">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 .. </span><br>
<span style="background:white">While in case of Centos 7.3
after running exec sudo command value of $USER gets
updated to root and it works fine</span></span></p>
</div>
</blockquote>
<br>
Don't check $USER, use the output from `id -u`<br>
<br>
Trevor<br>
</body>
</html>