admin posted an update 5 months, 2 weeks ago
HOW TO RUN SAME COMMAND ON MULTIPLE SCREEN SESSIONS – PARALLEL RUN COMMANDS WITH GNU SCREEN ON MULTIPLE SSH ACCESSED SERVERS
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”.