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)


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\""

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

  • 1
    Screen list, with or without sudo, is equal, so there is no such screen too. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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