Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question

migrated from Sep 10 '11 at 19:45

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

up vote 1 down vote accepted

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
# 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\""
share|improve this answer
Thanks, that helps – Frozen Spider Sep 19 '11 at 12:11

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

share|improve this answer
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .