Take the 2-minute tour ×

I have a GNU screen named demo, I want to send commands to it. How do I do this?

screen -S demo -X /home/aa/scripts/outputs.sh

yeilds No screen session found.

and doing screen -ls shows that it isn't running.

share|improve this question
are you in the right security context (id)? –  sehe May 19 '11 at 20:43
what does that mean? @sehe –  Kevin Duke May 19 '11 at 20:45
are you in the same user that created the screen session? –  sehe May 19 '11 at 20:53
@sehe yes, I am doing everything in the root account. –  Kevin Duke May 19 '11 at 20:54
where is the screen session (can you see it live while doing the -X command?) –  sehe May 19 '11 at 20:55

1 Answer 1

up vote 16 down vote accepted

If the Screen session isn't running, you won't be able to send things to it. Start it first.

Once you've got a session, you need to distinguish between Screen commands and keyboard input. screen -X expects a Screen command. The stuff command sends input, and if you want to run that program from a shell prompt, you'll have to pass a newline as well.

screen -S demo -X stuff '/home/aa/scripts/outputs.sh

Note that this may be the wrong approach. Are you sure you want to type into whatever is active in that session? To direct the input at a particular window, use

screen -S demo -p 1 -X stuff '/home/aa/scripts/outputs.sh

where 1 is the window number (you can use its title instead).

To start a new window in that session, use the screen command instead. (That's the screen Screen command, not the screen shell command.)

screen -S demo -p 1 -X screen '/home/aa/scripts/outputs.sh'
share|improve this answer
Thanks gilles. After I do what you wrote and reattach the screen I see this: /home/aa/scripts/outputs.sh however the script isn't running until I hit enter. Any suggestion on how to make the script execute as well? –  Kevin Duke May 19 '11 at 22:31
@Kevin: Sorry, I'd misplaced a quote. stuff and the text you want to send need to be in separate arguments. Note that there's newline inside the quotes. –  Gilles May 19 '11 at 23:12
awesome, thanks a lot! –  Kevin Duke May 19 '11 at 23:27
If you want to send commands that you would normally execute on the shell rather than in a script, you can add the (literal) ^M to the end of the line, e.g.: screen -S demo -p 1 -X stuff 'echo "hello"^M'. –  Steve Pike Oct 17 '11 at 13:24

Your Answer


