How to create a screen and execute a sudo command












1















I need a script to create a screen session and run a command inside, then detach and proceed with other screens. So I need something like screen -S vault -d -m $HOME/vault/v.sh. However, v.sh requires sudo privileges. What are my options?




  1. Leave it like that and run the whole script as sudo. Problem: the other scripts/sessions will also run as sudo, which is undesirable.

  2. Insert sudo at the start: sudo screen -S vault -d -m $HOME/vault/v.sh.

  3. Insert it before calling v.sh: screen -S vault -d -m "sudo $HOME/vault/v.sh"


What is the best option?










share|improve this question


















  • 1





    It depends on what you want to achieve. It's someone you have to make your mind up about. it looks like you know how to solve your problem. You even list some of the pro and con arguments.

    – Seth
    Jan 17 at 10:49











  • Well, I'm still a noob here, being a long time Windows user. So I definitely don't know what I'm doing.

    – ulu
    Jan 24 at 9:40
















1















I need a script to create a screen session and run a command inside, then detach and proceed with other screens. So I need something like screen -S vault -d -m $HOME/vault/v.sh. However, v.sh requires sudo privileges. What are my options?




  1. Leave it like that and run the whole script as sudo. Problem: the other scripts/sessions will also run as sudo, which is undesirable.

  2. Insert sudo at the start: sudo screen -S vault -d -m $HOME/vault/v.sh.

  3. Insert it before calling v.sh: screen -S vault -d -m "sudo $HOME/vault/v.sh"


What is the best option?










share|improve this question


















  • 1





    It depends on what you want to achieve. It's someone you have to make your mind up about. it looks like you know how to solve your problem. You even list some of the pro and con arguments.

    – Seth
    Jan 17 at 10:49











  • Well, I'm still a noob here, being a long time Windows user. So I definitely don't know what I'm doing.

    – ulu
    Jan 24 at 9:40














1












1








1








I need a script to create a screen session and run a command inside, then detach and proceed with other screens. So I need something like screen -S vault -d -m $HOME/vault/v.sh. However, v.sh requires sudo privileges. What are my options?




  1. Leave it like that and run the whole script as sudo. Problem: the other scripts/sessions will also run as sudo, which is undesirable.

  2. Insert sudo at the start: sudo screen -S vault -d -m $HOME/vault/v.sh.

  3. Insert it before calling v.sh: screen -S vault -d -m "sudo $HOME/vault/v.sh"


What is the best option?










share|improve this question














I need a script to create a screen session and run a command inside, then detach and proceed with other screens. So I need something like screen -S vault -d -m $HOME/vault/v.sh. However, v.sh requires sudo privileges. What are my options?




  1. Leave it like that and run the whole script as sudo. Problem: the other scripts/sessions will also run as sudo, which is undesirable.

  2. Insert sudo at the start: sudo screen -S vault -d -m $HOME/vault/v.sh.

  3. Insert it before calling v.sh: screen -S vault -d -m "sudo $HOME/vault/v.sh"


What is the best option?







ubuntu bash sudo gnu-screen






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 17 at 10:16









uluulu

1063




1063








  • 1





    It depends on what you want to achieve. It's someone you have to make your mind up about. it looks like you know how to solve your problem. You even list some of the pro and con arguments.

    – Seth
    Jan 17 at 10:49











  • Well, I'm still a noob here, being a long time Windows user. So I definitely don't know what I'm doing.

    – ulu
    Jan 24 at 9:40














  • 1





    It depends on what you want to achieve. It's someone you have to make your mind up about. it looks like you know how to solve your problem. You even list some of the pro and con arguments.

    – Seth
    Jan 17 at 10:49











  • Well, I'm still a noob here, being a long time Windows user. So I definitely don't know what I'm doing.

    – ulu
    Jan 24 at 9:40








1




1





It depends on what you want to achieve. It's someone you have to make your mind up about. it looks like you know how to solve your problem. You even list some of the pro and con arguments.

– Seth
Jan 17 at 10:49





It depends on what you want to achieve. It's someone you have to make your mind up about. it looks like you know how to solve your problem. You even list some of the pro and con arguments.

– Seth
Jan 17 at 10:49













Well, I'm still a noob here, being a long time Windows user. So I definitely don't know what I'm doing.

– ulu
Jan 24 at 9:40





Well, I'm still a noob here, being a long time Windows user. So I definitely don't know what I'm doing.

– ulu
Jan 24 at 9:40










1 Answer
1






active

oldest

votes


















0














One option you haven't listed is that if v.sh itself requires sudo privs, put that in the shebang line at the top of the script:



$ head -1 $HOME/vault/v.sh
#!/usr/bin/sudo /bin/sh


This method has the slight advantage that your master script doesn't require any knowledge of which scripts require sudo and which don't.






share|improve this answer


























  • The problem with putting sudo in v.sh is that it requires entering the password inside the screen. SO I have to manually go to the screen and enter it, which I'm trying to avoid.

    – ulu
    Jan 24 at 9:43











  • One way to get around that is to edit your sudoers file to allow your account to run the script without entering a password. A line in your sudoers file like ulu ALL=(root) NOPASSWD: /bin/bash /home/ulu/vault/v.sh might be what you need.

    – Jim L.
    Jan 25 at 21:39













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1395311%2fhow-to-create-a-screen-and-execute-a-sudo-command%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














One option you haven't listed is that if v.sh itself requires sudo privs, put that in the shebang line at the top of the script:



$ head -1 $HOME/vault/v.sh
#!/usr/bin/sudo /bin/sh


This method has the slight advantage that your master script doesn't require any knowledge of which scripts require sudo and which don't.






share|improve this answer


























  • The problem with putting sudo in v.sh is that it requires entering the password inside the screen. SO I have to manually go to the screen and enter it, which I'm trying to avoid.

    – ulu
    Jan 24 at 9:43











  • One way to get around that is to edit your sudoers file to allow your account to run the script without entering a password. A line in your sudoers file like ulu ALL=(root) NOPASSWD: /bin/bash /home/ulu/vault/v.sh might be what you need.

    – Jim L.
    Jan 25 at 21:39


















0














One option you haven't listed is that if v.sh itself requires sudo privs, put that in the shebang line at the top of the script:



$ head -1 $HOME/vault/v.sh
#!/usr/bin/sudo /bin/sh


This method has the slight advantage that your master script doesn't require any knowledge of which scripts require sudo and which don't.






share|improve this answer


























  • The problem with putting sudo in v.sh is that it requires entering the password inside the screen. SO I have to manually go to the screen and enter it, which I'm trying to avoid.

    – ulu
    Jan 24 at 9:43











  • One way to get around that is to edit your sudoers file to allow your account to run the script without entering a password. A line in your sudoers file like ulu ALL=(root) NOPASSWD: /bin/bash /home/ulu/vault/v.sh might be what you need.

    – Jim L.
    Jan 25 at 21:39
















0












0








0







One option you haven't listed is that if v.sh itself requires sudo privs, put that in the shebang line at the top of the script:



$ head -1 $HOME/vault/v.sh
#!/usr/bin/sudo /bin/sh


This method has the slight advantage that your master script doesn't require any knowledge of which scripts require sudo and which don't.






share|improve this answer















One option you haven't listed is that if v.sh itself requires sudo privs, put that in the shebang line at the top of the script:



$ head -1 $HOME/vault/v.sh
#!/usr/bin/sudo /bin/sh


This method has the slight advantage that your master script doesn't require any knowledge of which scripts require sudo and which don't.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 18 at 19:27

























answered Jan 18 at 18:57









Jim L.Jim L.

42117




42117













  • The problem with putting sudo in v.sh is that it requires entering the password inside the screen. SO I have to manually go to the screen and enter it, which I'm trying to avoid.

    – ulu
    Jan 24 at 9:43











  • One way to get around that is to edit your sudoers file to allow your account to run the script without entering a password. A line in your sudoers file like ulu ALL=(root) NOPASSWD: /bin/bash /home/ulu/vault/v.sh might be what you need.

    – Jim L.
    Jan 25 at 21:39





















  • The problem with putting sudo in v.sh is that it requires entering the password inside the screen. SO I have to manually go to the screen and enter it, which I'm trying to avoid.

    – ulu
    Jan 24 at 9:43











  • One way to get around that is to edit your sudoers file to allow your account to run the script without entering a password. A line in your sudoers file like ulu ALL=(root) NOPASSWD: /bin/bash /home/ulu/vault/v.sh might be what you need.

    – Jim L.
    Jan 25 at 21:39



















The problem with putting sudo in v.sh is that it requires entering the password inside the screen. SO I have to manually go to the screen and enter it, which I'm trying to avoid.

– ulu
Jan 24 at 9:43





The problem with putting sudo in v.sh is that it requires entering the password inside the screen. SO I have to manually go to the screen and enter it, which I'm trying to avoid.

– ulu
Jan 24 at 9:43













One way to get around that is to edit your sudoers file to allow your account to run the script without entering a password. A line in your sudoers file like ulu ALL=(root) NOPASSWD: /bin/bash /home/ulu/vault/v.sh might be what you need.

– Jim L.
Jan 25 at 21:39







One way to get around that is to edit your sudoers file to allow your account to run the script without entering a password. A line in your sudoers file like ulu ALL=(root) NOPASSWD: /bin/bash /home/ulu/vault/v.sh might be what you need.

– Jim L.
Jan 25 at 21:39




















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1395311%2fhow-to-create-a-screen-and-execute-a-sudo-command%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар