user1713003
user1713003

Reputation: 21

Scripting screen for multiple deattached windows

I've combed through as many of the gnu-screen and bash tags as I can find and I can't quite find the answer, so forgive me if I've missed an obvious one.

As part of a bash script, I need to create a deattached screen session and have it run a command in the newly created window 1 of that session, then another command in the newly created window 2, all part of the same session. What I have so far successfully creates the session deattached, names it, and gets my python script running in window 1. The problem is that it will never open a second window. What am I missing?

screen -d -m -S jsession
screen -S jsession -p 0 -X exec /script/pyscript.py
screen -S jsession -p 1 -X exec asterisk -rvvvvvvvvvv

Upvotes: 2

Views: 2474

Answers (1)

chepner
chepner

Reputation: 531808

You need to create the second window before you can send a command to it. The first window is created when the session is started, which is why the first exec works. For the other window, just replace exec with screen, to start the new window.

screen -d -m -S jsession
screen -S jsession -p 0 -X exec /script/pyscript.py

# No need to specify a window with -p; the new one will be numbered
# automatically
screen -S jsession -X screen asterisk -rvvvvvvvvvv

Upvotes: 1

Related Questions