While under root user (printed by whoami), execution of

sh -c "screen -d -m -S testscreen sh -c \"echo asd; echo qwe\""

creates a screen with two lines output, which can be reattached via screen -r testcreen

But if I'm using

sudo -n -u root sh -c "screen -d -m -S testscreen sh -c \"echo asd; echo qwe\""

the screen does not appear in list. What's wrong and what should I do instead?

(CentOS 5.2)

link|improve this question
feedback

migrated from stackoverflow.com Sep 10 '11 at 19:45

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 1 down vote accepted
+50

It sounds like your screen binary location is not in the $PATH being used by sh. So when you sudo, because you aren't invoking the login shell to setup a new environment, the command won't exist. You can verify this by checking a couple things.

become root:

$ sudo -s
# which screen
/some/path/to/screen
# echo $PATH

The easiest way to fix this is to specify the full path to screen in the command you are using:

$ sudo -n -u root sh -c "/some/path/to/screen -d -m -S testscreen sh -c \"echo asd; echo qwe\""

If that doesn't fix it, it would be helpful to capture if sh is having some other issue starting the screen by doing:

$ sudo -n -u root sh -c "set -x ; screen -d -m -S testscreen sh -c \"echo asd; echo qwe\""
link|improve this answer
Thanks, that helps – Frozen Spider Sep 19 '11 at 12:11
feedback

The screen is added to the root user, use sudo screen -raAd to reattach

link|improve this answer
1  
Screen list, with or without sudo, is equal, so there is no such screen too. – Frozen Spider Sep 10 '11 at 5:46
Don't have a Linux box around atm, can't test it. – Ravi Sep 10 '11 at 5:50
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.