-   Linux - Software (
-   -   Input to a screen session from a script running outside (

Skaperen 08-01-2012 06:15 PM

Input to a screen session from a script running outside
I know I can start a background screen session and specify a program using a command like:

screen -dmS sessionname program args ...
But what I would also like for the script to do is wait a few seconds and then provide some terminal input to what is running in that session, just as if it had been typed in, but without actually displaying that session or being stuck in it.

The purpose is to start something running in the screen session automatically, along with the initial input. An example would be starting a regular interactive shell, then feeding the first command to that shell through screen, with the expectation of later connecting to that session, see the results, and type more.

Pretending that an option "--input" existed (that causes its command line arguments to be entered to the session), the script could do:

screen -dmS sessionname
sleep 9
screen --input -S sessionname ssh me@remotehost\n
sleep 3
screen --input -S sessionname mypassword\n

And then I could later connect to that session with a shell on the remote host that I can type commands on, and if/when I exit that shell, have a shell on the local host.

Being able to take a snapshot of that screen session display contents, written to a file or stdout, would be nice plus.

All times are GMT -5. The time now is 04:22 AM.