I have a work environment on my Ubuntu laptop in which I want to use three different screens.
Eg. in terminal, I usually write
screen -S mywork
run_server_1
then, ctrl-a c to create a second screen
run_server_2
etc.
I'd like to write a script to automate setting up this environment, but how can I control multiple screens from one script?
Update : I really want to be able to do this from a shell script, not a screen config. file. Is there a way to do that?
Reading man pages and tutorials helps
I would say that you want to do is create a file $HOME/.screenrc.multiwin
Then running
will do what you need
Commands can be passed from outside using
screen -S sessionname -X command
for instancescreen -S mywork -X screen run_server_2
would create a new window (same asctrl-a c
) but that window would have run_server_2 executing in it. Unlike doing it by hand,there will not be a shell running in that window, so when run_server_2 exits, the window will be closed.Controlling multiple screens is simply a matter of making sure they're all named with -S
I believe tmux is much more easily scriptable than screen for this type of purpose. tmux program accepts its own commands as arguments on the command line, so for example, to launch two windows: "tmux new-session -d '/bin/bash' \; new-window -d 'top'". In the first window, it will run an interactive "bash" shell, and in the second window it will run "top".