Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send commands to a GNU screen

Tags:

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.

like image 790
dukevin Avatar asked May 19 '11 20:05

dukevin


People also ask

How do I send commands to my screen?

Sending commands to screenscreen has the -X flag which allows you to send a (screen) command to a session. The -p 0 flag is for the window inside screen. If you have created multiple windows ( CTRL+A c ) you can specify the number. With CTRL+A [0-9] you can directly go to that window inside screen.

How do you send Ctrl C to screen?

If you want to send something to all the windows, use # (needs to be quoted) as the window_number. UPDATE: Screen's stuff command also supports ^X (or ^x ) to mean CTRL-X so the following command can also be used to send CTRL-C .

What is the command used for easy using of GNU screen?

Log files of current screen sessions can be started with the Ctrl+a H command, which will make a file called screenlog. X where X is the number of your screen session. A screenshot of what is currently in your screen window can be invoked with Ctrl+a h, creating a file called hardcopy.


1 Answers

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' 
like image 166
Gilles 'SO- stop being evil' Avatar answered Sep 27 '22 21:09

Gilles 'SO- stop being evil'