0

In the answer to this post Corey Henderson explains how you can use the at and stuff commands in screen to send commands to all windows of a screen session at once. I would like to know how I can stuff the input buffers to some windows at the same time. In other words, I would like to use a filter to specify which windows should receive the input and which should not.

It would be great if I could filter on the window number instead of the user name or the window name because bash likes to change the window name sometimes and it is inconvenient to modify the .bashrc on multiple machines. Also, sometimes I don't have control over which user I am running the command as.

So far I have only been able to run a command on either the currently active window or all windows at once.

Chancelot
  • 63
  • 1
  • 5

1 Answers1

1

The only way I have found to do windows filtering when using the atcommand is by using windows names.

By default screen's windows names are set after the actual command name of the program created in the window, for me this is usually bash. But windows names can be changed to whatever you prefer with Ctrl+A. If your windows' names change dynamically, check you don't have Dynamic Titles enabled.

So in practice that means you can give related windows a common prefix and then use at "prefix#" stuff "command" to execute the command only on those windows whose names matches the filter.

Imagine we have the following windows opened in our screen session:

0$ front1 - 1$ front2 - 2$ back1 - 3$ back2 - 4$ back3 - 5$ db1 - 6$ db2

The next command would send the service ntpd stop command to windows starting by the string back, that is back1, back2, back3:

at "back#" stuff "service ntpd stop^M"
Fred Astair
  • 121
  • 1
  • 4