To get super user name in shell script [duplicate]

Clash Royale CLAN TAG#URR8PPP
This question already has an answer here:
proceed execution of script after change user
3 answers
Why doesn't “sudo su” in a shell script run the rest of the script as root?
4 answers
I am having a bash shell script (eg - test.sh). In this shell script I have below statements-
sudo su - dbmanage
echo `whoami` >>$LOGFILE
when I execute the script by login with my account "mukesh" --in logfile ($LOGFILE) I am getting "mukesh". However, I am expecting to get "dbmanage".
But, at the same time on bash terminal - when I execute this - I am getting "dbmanage"
-bash-3.2$ sudo su - dbmanage
-bash-3.2$ whoami
dbmanage
bash sudo
marked as duplicate by Jeff Schaller♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Feb 28 at 14:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
proceed execution of script after change user
3 answers
Why doesn't “sudo su” in a shell script run the rest of the script as root?
4 answers
I am having a bash shell script (eg - test.sh). In this shell script I have below statements-
sudo su - dbmanage
echo `whoami` >>$LOGFILE
when I execute the script by login with my account "mukesh" --in logfile ($LOGFILE) I am getting "mukesh". However, I am expecting to get "dbmanage".
But, at the same time on bash terminal - when I execute this - I am getting "dbmanage"
-bash-3.2$ sudo su - dbmanage
-bash-3.2$ whoami
dbmanage
bash sudo
marked as duplicate by Jeff Schaller♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Feb 28 at 14:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Are you trying to redirect the output in the file named LOGFILE ? If yes, i think you do not need the $ before the file name.
– Atul
Feb 28 at 14:40
Yes, I am redirecting output into a logfile
– Sanjay
Feb 28 at 14:55
add a comment |
This question already has an answer here:
proceed execution of script after change user
3 answers
Why doesn't “sudo su” in a shell script run the rest of the script as root?
4 answers
I am having a bash shell script (eg - test.sh). In this shell script I have below statements-
sudo su - dbmanage
echo `whoami` >>$LOGFILE
when I execute the script by login with my account "mukesh" --in logfile ($LOGFILE) I am getting "mukesh". However, I am expecting to get "dbmanage".
But, at the same time on bash terminal - when I execute this - I am getting "dbmanage"
-bash-3.2$ sudo su - dbmanage
-bash-3.2$ whoami
dbmanage
bash sudo
This question already has an answer here:
proceed execution of script after change user
3 answers
Why doesn't “sudo su” in a shell script run the rest of the script as root?
4 answers
I am having a bash shell script (eg - test.sh). In this shell script I have below statements-
sudo su - dbmanage
echo `whoami` >>$LOGFILE
when I execute the script by login with my account "mukesh" --in logfile ($LOGFILE) I am getting "mukesh". However, I am expecting to get "dbmanage".
But, at the same time on bash terminal - when I execute this - I am getting "dbmanage"
-bash-3.2$ sudo su - dbmanage
-bash-3.2$ whoami
dbmanage
This question already has an answer here:
proceed execution of script after change user
3 answers
Why doesn't “sudo su” in a shell script run the rest of the script as root?
4 answers
bash sudo
bash sudo
edited Mar 1 at 2:49
Rui F Ribeiro
41.8k1483142
41.8k1483142
asked Feb 28 at 14:29
SanjaySanjay
142
142
marked as duplicate by Jeff Schaller♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Feb 28 at 14:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Jeff Schaller♦
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Feb 28 at 14:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Are you trying to redirect the output in the file named LOGFILE ? If yes, i think you do not need the $ before the file name.
– Atul
Feb 28 at 14:40
Yes, I am redirecting output into a logfile
– Sanjay
Feb 28 at 14:55
add a comment |
Are you trying to redirect the output in the file named LOGFILE ? If yes, i think you do not need the $ before the file name.
– Atul
Feb 28 at 14:40
Yes, I am redirecting output into a logfile
– Sanjay
Feb 28 at 14:55
Are you trying to redirect the output in the file named LOGFILE ? If yes, i think you do not need the $ before the file name.
– Atul
Feb 28 at 14:40
Are you trying to redirect the output in the file named LOGFILE ? If yes, i think you do not need the $ before the file name.
– Atul
Feb 28 at 14:40
Yes, I am redirecting output into a logfile
– Sanjay
Feb 28 at 14:55
Yes, I am redirecting output into a logfile
– Sanjay
Feb 28 at 14:55
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Are you trying to redirect the output in the file named LOGFILE ? If yes, i think you do not need the $ before the file name.
– Atul
Feb 28 at 14:40
Yes, I am redirecting output into a logfile
– Sanjay
Feb 28 at 14:55