In Screen, How to Send a Command to All Virtual Terminal Windows Within a Single Screen Session

in Screen, how do I send a command to all virtual terminal windows within a single screen session?

I found a good tutorial here to do this:

http://blog.cone.be/2009/11/24/gnu-screen-nethack-different-screen-windows-sending-commands-to-all-screen-windows/

From the post:

Once you re used to the multiple windows, you might run into a situation where you want to send a same command to several of these open windows. Screen provides in the “at” command to do this. First you ll need to open command line mode.

C-a : (colon) Enter command line mode.

This way you can type a command once, but you ll still have to enter each separate window. But there is a better way. As an example we ‘ll send “ls -l” to all the windows.

at "#" stuff "ls -l^M"

This command is barely readable, so let's pick it apart! The first part is 'at [identifier][#|*|%] command'. The at command sends the text parameter to all the windows you specified in the identifier. You can match the criteria to either the window name or number with #, the user name with * or the displays, using %. The next part is the command you want to run in the selected windows. We’re using "stuff" to stuff the command we want to execute into the input buffer of the selected windows. Stuff is really straightforward. It simply stuffs the string you gave as a parameter. Next problem is the command. Or rather having it executed! To get screen to put an “enter” after the command, to execute the command, add “^M” at the end. You can do a lot more with this than just sending an ls to the input. Any screen command, like renaming, moving windows around, whatnot .. is available in combination with "at".

Bash script to generate four terminals attached to the same screen session

I've tried your code, came up with this:

#!/bin/bash

for i in {1..4}
do
gnome-terminal --window-with-profile=hdesk$i -e 'screen -S hdesk'$i
done

screen -XS hdesk1 stuff 'top^M'

for i in {2..4}
do
screen -XS hdesk$i stuff 'screen -x hdesk1^M'
sleep 1
done

I have no idea why this works, maybe screen refuses to attach too fast?

Python OS X how to have script launch in parallel in multiple terminal windows

An easy way to do this would be to run the scripts in the background, which is actually pretty simple. Just append an & to the end of your call (sending the command to the background) and you can run them all in the same terminal:

python trigger.py [params] &

You could even compile a bash script to start all of them simultaneously with one command. You could also use this to aggregate return values into one place for ease of use:

miner.sh

#!/bin/bash
python trigger.py [params1] &
python trigger.py [params2] &
#etc

Visual Studio Code open tab in new window

On Windows and Linux, press CTRL+K, then release the keys and press O (the letter O, not Zero).

On macOS, press CMD+K, then O (without holding CMD).

This will open the active file tab in a new window/instance.



Related Topics



Leave a reply



Submit