I read How can I start multiple screen sessions automatically?, but I don't understand the first accepted reply:
screen -dmS "$SESSION_NAME" "$COMMAND" "$ARGUMENTS"
In my case I need to automatically create one screen session for one script, and afterwards I need to create a new window in the same session for another script. Manually, I would:
- run screen
- enter command
- CTRL+A
- CTRL+C
- enter command
- CTRL+A
- CTRL+D
How can I do this automatically in a script? A simple example would help me a lot.
Thank you for replies.
Best Answer
I'm not exactly sure what you want to happen - do you want a script that creates the screen session with two windows for two commands, or do you want to run a script in a screen window that runs one command, then creates a new window for the second one?
The second one's easy, so let's start with that:
Running "screen " within screen will create a new window in the current session, not start a new one. But it will return immediately, so after the last line there, the script will exit while command2 is still running. And when command2 is done, its window will close.
The first interpretation of your question a bit harder anyway, so let's go ahead and solve the above while at it:
The script will launch
command1
, wait until it's done, then launchcommand2
and exit. As if you'd runcommand1 ; command2 &
, but with the output elsewhere. I'm sure you can figure out how to runcommand1
in the background.