sudo nohup and redirection

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Trying to figure out the correct Cmnd_Alias for the sudoers file



The command i which to run without any password is the following:



sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


The lines i have added to sudoers file is:



## Cmnd alias specification
Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
Cmnd_Alias AXTOOLTTYSTOP = /etc/init.d/axtty stop
Cmnd_Alias AXTOOLTTYSTATUS = /etc/init.d/axtty status
Cmnd_Alias AXTOOLINTCTLSTART = /sbin/initctl start ttyp?
Cmnd_Alias AXTOOLINTCTLSTOP = /sbin/initctl stop ttyp?

## This will disable password request for the axtools commands
%sudoaxtools ALL=(root) NOPASSWD: AXTOOLTTYSTART, AXTOOLTTYSTOP, AXTOOLTTYSTATUS, AXTOOLINTCTLSTART, AXTOOLINTCTLSTOP
Defaults!AXTOOLTTYSTART !requiretty
Defaults!AXTOOLTTYSTOP !requiretty


The command in mention is ran inside a script (axopen), executed either by member of group sudoaxtools or root's crontab



/usr/local/bin/axopen



#!/bin/sh

SUDO=''
if (( $EUID != 0 )); then
SUDO='sudo'
fi

echo -n "Checking for open connections"
while netstat -d | grep -q axel
do
((c++)) && ((c==900)) && break
echo -n "."
sleep 4
done
echo "done"

echo "Starting axtty service.."
$SUDO /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
sleep 4
$SUDO /etc/init.d/axtty status


When axopen is executed på member of sudoaxtools, then it still prompts for password. I expect its because of the >/dev/null 2>&1 pieces.



Secondary



The reason i'm using nohup is because the service for some reason will not start, when executed simply using



sudo /etc/init.d/axtty start


So if someone have ideas to fix that, it will be great as well.







share|improve this question



















  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Jul 22 at 13:53














up vote
1
down vote

favorite












Trying to figure out the correct Cmnd_Alias for the sudoers file



The command i which to run without any password is the following:



sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


The lines i have added to sudoers file is:



## Cmnd alias specification
Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
Cmnd_Alias AXTOOLTTYSTOP = /etc/init.d/axtty stop
Cmnd_Alias AXTOOLTTYSTATUS = /etc/init.d/axtty status
Cmnd_Alias AXTOOLINTCTLSTART = /sbin/initctl start ttyp?
Cmnd_Alias AXTOOLINTCTLSTOP = /sbin/initctl stop ttyp?

## This will disable password request for the axtools commands
%sudoaxtools ALL=(root) NOPASSWD: AXTOOLTTYSTART, AXTOOLTTYSTOP, AXTOOLTTYSTATUS, AXTOOLINTCTLSTART, AXTOOLINTCTLSTOP
Defaults!AXTOOLTTYSTART !requiretty
Defaults!AXTOOLTTYSTOP !requiretty


The command in mention is ran inside a script (axopen), executed either by member of group sudoaxtools or root's crontab



/usr/local/bin/axopen



#!/bin/sh

SUDO=''
if (( $EUID != 0 )); then
SUDO='sudo'
fi

echo -n "Checking for open connections"
while netstat -d | grep -q axel
do
((c++)) && ((c==900)) && break
echo -n "."
sleep 4
done
echo "done"

echo "Starting axtty service.."
$SUDO /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
sleep 4
$SUDO /etc/init.d/axtty status


When axopen is executed på member of sudoaxtools, then it still prompts for password. I expect its because of the >/dev/null 2>&1 pieces.



Secondary



The reason i'm using nohup is because the service for some reason will not start, when executed simply using



sudo /etc/init.d/axtty start


So if someone have ideas to fix that, it will be great as well.







share|improve this question



















  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Jul 22 at 13:53












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Trying to figure out the correct Cmnd_Alias for the sudoers file



The command i which to run without any password is the following:



sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


The lines i have added to sudoers file is:



## Cmnd alias specification
Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
Cmnd_Alias AXTOOLTTYSTOP = /etc/init.d/axtty stop
Cmnd_Alias AXTOOLTTYSTATUS = /etc/init.d/axtty status
Cmnd_Alias AXTOOLINTCTLSTART = /sbin/initctl start ttyp?
Cmnd_Alias AXTOOLINTCTLSTOP = /sbin/initctl stop ttyp?

## This will disable password request for the axtools commands
%sudoaxtools ALL=(root) NOPASSWD: AXTOOLTTYSTART, AXTOOLTTYSTOP, AXTOOLTTYSTATUS, AXTOOLINTCTLSTART, AXTOOLINTCTLSTOP
Defaults!AXTOOLTTYSTART !requiretty
Defaults!AXTOOLTTYSTOP !requiretty


The command in mention is ran inside a script (axopen), executed either by member of group sudoaxtools or root's crontab



/usr/local/bin/axopen



#!/bin/sh

SUDO=''
if (( $EUID != 0 )); then
SUDO='sudo'
fi

echo -n "Checking for open connections"
while netstat -d | grep -q axel
do
((c++)) && ((c==900)) && break
echo -n "."
sleep 4
done
echo "done"

echo "Starting axtty service.."
$SUDO /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
sleep 4
$SUDO /etc/init.d/axtty status


When axopen is executed på member of sudoaxtools, then it still prompts for password. I expect its because of the >/dev/null 2>&1 pieces.



Secondary



The reason i'm using nohup is because the service for some reason will not start, when executed simply using



sudo /etc/init.d/axtty start


So if someone have ideas to fix that, it will be great as well.







share|improve this question











Trying to figure out the correct Cmnd_Alias for the sudoers file



The command i which to run without any password is the following:



sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


The lines i have added to sudoers file is:



## Cmnd alias specification
Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
Cmnd_Alias AXTOOLTTYSTOP = /etc/init.d/axtty stop
Cmnd_Alias AXTOOLTTYSTATUS = /etc/init.d/axtty status
Cmnd_Alias AXTOOLINTCTLSTART = /sbin/initctl start ttyp?
Cmnd_Alias AXTOOLINTCTLSTOP = /sbin/initctl stop ttyp?

## This will disable password request for the axtools commands
%sudoaxtools ALL=(root) NOPASSWD: AXTOOLTTYSTART, AXTOOLTTYSTOP, AXTOOLTTYSTATUS, AXTOOLINTCTLSTART, AXTOOLINTCTLSTOP
Defaults!AXTOOLTTYSTART !requiretty
Defaults!AXTOOLTTYSTOP !requiretty


The command in mention is ran inside a script (axopen), executed either by member of group sudoaxtools or root's crontab



/usr/local/bin/axopen



#!/bin/sh

SUDO=''
if (( $EUID != 0 )); then
SUDO='sudo'
fi

echo -n "Checking for open connections"
while netstat -d | grep -q axel
do
((c++)) && ((c==900)) && break
echo -n "."
sleep 4
done
echo "done"

echo "Starting axtty service.."
$SUDO /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
sleep 4
$SUDO /etc/init.d/axtty status


When axopen is executed på member of sudoaxtools, then it still prompts for password. I expect its because of the >/dev/null 2>&1 pieces.



Secondary



The reason i'm using nohup is because the service for some reason will not start, when executed simply using



sudo /etc/init.d/axtty start


So if someone have ideas to fix that, it will be great as well.









share|improve this question










share|improve this question




share|improve this question









asked Jul 12 at 12:18









Phliplip

1066




1066











  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Jul 22 at 13:53
















  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Jul 22 at 13:53















If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Jul 22 at 13:53




If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Jul 22 at 13:53










2 Answers
2






active

oldest

votes

















up vote
3
down vote













You don't want the redirections as part of the sudo rule. /etc/sudoers contains the program that is executed, and the redirections happen separately (at the containing shell level) from the sudo command:




(shell) sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1




This calls sudo and redirects the output; sudo sees:




(sudo) /usr/bin/nohup /etc/init.d/axtty start




Change this sudoers line:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


to:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start





share|improve this answer





















  • The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script?
    – Phliplip
    Jul 13 at 6:48






  • 1




    Leave the redirection in the script but take it out of sudoers.
    – Jeff Schaller
    Jul 13 at 10:01

















up vote
0
down vote



accepted










I ended up putting the nohup script in a seperate bash script.



/usr/local/bin/axttystart



#!/bin/sh

## Intermediate bashscript in order to sudo nohup properly
/usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


Then changed sudo'ers line containing the Cmnd_alias for AXTOOLTTYSTART to



Cmnd_Alias AXTOOLTTYSTART = /usr/local/bin/axttystart


The updated axopen script will instead for the sudoing the nohup line directly, sudo the axttystart script



#!/bin/sh

[...]

echo "Starting axtty service.."
$SUDO /usr/local/bin/axttystart
sleep 4
$SUDO /etc/init.d/axtty status





share|improve this answer























  • Woops... You're correct, copy-paste mistake :-)
    – Phliplip
    Jul 15 at 21:28










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454882%2fsudo-nohup-and-redirection%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













You don't want the redirections as part of the sudo rule. /etc/sudoers contains the program that is executed, and the redirections happen separately (at the containing shell level) from the sudo command:




(shell) sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1




This calls sudo and redirects the output; sudo sees:




(sudo) /usr/bin/nohup /etc/init.d/axtty start




Change this sudoers line:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


to:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start





share|improve this answer





















  • The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script?
    – Phliplip
    Jul 13 at 6:48






  • 1




    Leave the redirection in the script but take it out of sudoers.
    – Jeff Schaller
    Jul 13 at 10:01














up vote
3
down vote













You don't want the redirections as part of the sudo rule. /etc/sudoers contains the program that is executed, and the redirections happen separately (at the containing shell level) from the sudo command:




(shell) sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1




This calls sudo and redirects the output; sudo sees:




(sudo) /usr/bin/nohup /etc/init.d/axtty start




Change this sudoers line:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


to:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start





share|improve this answer





















  • The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script?
    – Phliplip
    Jul 13 at 6:48






  • 1




    Leave the redirection in the script but take it out of sudoers.
    – Jeff Schaller
    Jul 13 at 10:01












up vote
3
down vote










up vote
3
down vote









You don't want the redirections as part of the sudo rule. /etc/sudoers contains the program that is executed, and the redirections happen separately (at the containing shell level) from the sudo command:




(shell) sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1




This calls sudo and redirects the output; sudo sees:




(sudo) /usr/bin/nohup /etc/init.d/axtty start




Change this sudoers line:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


to:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start





share|improve this answer













You don't want the redirections as part of the sudo rule. /etc/sudoers contains the program that is executed, and the redirections happen separately (at the containing shell level) from the sudo command:




(shell) sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1




This calls sudo and redirects the output; sudo sees:




(sudo) /usr/bin/nohup /etc/init.d/axtty start




Change this sudoers line:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


to:



Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start






share|improve this answer













share|improve this answer



share|improve this answer











answered Jul 12 at 12:32









Jeff Schaller

30.8k846104




30.8k846104











  • The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script?
    – Phliplip
    Jul 13 at 6:48






  • 1




    Leave the redirection in the script but take it out of sudoers.
    – Jeff Schaller
    Jul 13 at 10:01
















  • The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script?
    – Phliplip
    Jul 13 at 6:48






  • 1




    Leave the redirection in the script but take it out of sudoers.
    – Jeff Schaller
    Jul 13 at 10:01















The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script?
– Phliplip
Jul 13 at 6:48




The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script?
– Phliplip
Jul 13 at 6:48




1




1




Leave the redirection in the script but take it out of sudoers.
– Jeff Schaller
Jul 13 at 10:01




Leave the redirection in the script but take it out of sudoers.
– Jeff Schaller
Jul 13 at 10:01












up vote
0
down vote



accepted










I ended up putting the nohup script in a seperate bash script.



/usr/local/bin/axttystart



#!/bin/sh

## Intermediate bashscript in order to sudo nohup properly
/usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


Then changed sudo'ers line containing the Cmnd_alias for AXTOOLTTYSTART to



Cmnd_Alias AXTOOLTTYSTART = /usr/local/bin/axttystart


The updated axopen script will instead for the sudoing the nohup line directly, sudo the axttystart script



#!/bin/sh

[...]

echo "Starting axtty service.."
$SUDO /usr/local/bin/axttystart
sleep 4
$SUDO /etc/init.d/axtty status





share|improve this answer























  • Woops... You're correct, copy-paste mistake :-)
    – Phliplip
    Jul 15 at 21:28














up vote
0
down vote



accepted










I ended up putting the nohup script in a seperate bash script.



/usr/local/bin/axttystart



#!/bin/sh

## Intermediate bashscript in order to sudo nohup properly
/usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


Then changed sudo'ers line containing the Cmnd_alias for AXTOOLTTYSTART to



Cmnd_Alias AXTOOLTTYSTART = /usr/local/bin/axttystart


The updated axopen script will instead for the sudoing the nohup line directly, sudo the axttystart script



#!/bin/sh

[...]

echo "Starting axtty service.."
$SUDO /usr/local/bin/axttystart
sleep 4
$SUDO /etc/init.d/axtty status





share|improve this answer























  • Woops... You're correct, copy-paste mistake :-)
    – Phliplip
    Jul 15 at 21:28












up vote
0
down vote



accepted







up vote
0
down vote



accepted






I ended up putting the nohup script in a seperate bash script.



/usr/local/bin/axttystart



#!/bin/sh

## Intermediate bashscript in order to sudo nohup properly
/usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


Then changed sudo'ers line containing the Cmnd_alias for AXTOOLTTYSTART to



Cmnd_Alias AXTOOLTTYSTART = /usr/local/bin/axttystart


The updated axopen script will instead for the sudoing the nohup line directly, sudo the axttystart script



#!/bin/sh

[...]

echo "Starting axtty service.."
$SUDO /usr/local/bin/axttystart
sleep 4
$SUDO /etc/init.d/axtty status





share|improve this answer















I ended up putting the nohup script in a seperate bash script.



/usr/local/bin/axttystart



#!/bin/sh

## Intermediate bashscript in order to sudo nohup properly
/usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1


Then changed sudo'ers line containing the Cmnd_alias for AXTOOLTTYSTART to



Cmnd_Alias AXTOOLTTYSTART = /usr/local/bin/axttystart


The updated axopen script will instead for the sudoing the nohup line directly, sudo the axttystart script



#!/bin/sh

[...]

echo "Starting axtty service.."
$SUDO /usr/local/bin/axttystart
sleep 4
$SUDO /etc/init.d/axtty status






share|improve this answer















share|improve this answer



share|improve this answer








edited Jul 15 at 21:27


























answered Jul 15 at 20:47









Phliplip

1066




1066











  • Woops... You're correct, copy-paste mistake :-)
    – Phliplip
    Jul 15 at 21:28
















  • Woops... You're correct, copy-paste mistake :-)
    – Phliplip
    Jul 15 at 21:28















Woops... You're correct, copy-paste mistake :-)
– Phliplip
Jul 15 at 21:28




Woops... You're correct, copy-paste mistake :-)
– Phliplip
Jul 15 at 21:28












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454882%2fsudo-nohup-and-redirection%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay