这个命令几乎不可读,所以让我们把它拆开!第一部分是“at [identifier][#|*|%] command”。 at 命令将文本参数发送到您在标识符中指定的所有窗口。您可以将条件与窗口名称或编号(带 #)、用户名(带 *)或显示器(使用 %)相匹配。下一部分是您要在选定窗口中运行的命令。我们使用“stuff”将我们想要执行的命令填充到所选窗口的输入缓冲区中。事情真的很简单。它只是填充您作为参数提供的字符串。下一个问题是命令。或者更确切地说,让它被执行!要让屏幕在命令后面输入“enter”,要执行命令,请在末尾添加“^M”。您可以用它做更多的事情,而不仅仅是向输入发送 ls 。任何屏幕命令,例如重命名、移动窗口等等......都可以与“at”组合使用。
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".
Sorry for this belated reply, but tmux might be a better choice for you than screen. In tmux, you have to press: C-b : to enter the command mode and input: setw synchronize-panes (or just setw sync<Tab> using autocompletion). Note that this command enables synchronization between panes (areas of one split screen, visible simultaneously), but not between windows (full, not split, screens).
You may also want to send to selected windows only (multicast).
Convention: Give 1st character of window title the meaning of a broadcast flag. E.g. if title starts with "." then the window listens to broadcast, otherwise it doesn't.
Set titles as needed.
screen -S SessionName -p 0 -X title "remote_0" # window 0: ignore multicast
screen -S SessionName -p 1 -X title ".remote_1" # window 1: listen to multicast
Send contents to listeners with the at command of screen
screen -S SessionName -X at ".#" stuff "date
"
Note: the ending double quote above ensures a ^M to be sent (Cr).
You may enable / disable multicast based on window title this way.
发布评论
评论(3)
我在这里找到了一个很好的教程来执行此操作:
http://blog.cone.be/2009/11/24/gnu-screen-nethack- Different-screen-windows-sending-commands-to-all-screen-windows/
来自帖子:
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:
抱歉回复迟了,但是
tmux
对您来说可能比screen
更好。在tmux
中,您必须按:Cb :
进入命令模式并输入:setw Synchronize-panes
(或者只是setw使用自动完成同步
)。请注意,此命令启用窗格(一个分屏的区域,同时可见)之间的同步,但不能启用窗口(全屏、非分屏)之间的同步。Sorry for this belated reply, but
tmux
might be a better choice for you thanscreen
. Intmux
, you have to press:C-b :
to enter the command mode and input:setw synchronize-panes
(or justsetw sync<Tab>
using autocompletion). Note that this command enables synchronization between panes (areas of one split screen, visible simultaneously), but not between windows (full, not split, screens).您可能还想仅发送到选定的窗口(多播)。
根据需要设置标题。
通过screen的at命令发送内容给听众
注意:上面的结尾双引号确保发送 ^M (Cr)。
您可以通过这种方式启用/禁用基于窗口标题的多播。
You may also want to send to selected windows only (multicast).
Set titles as needed.
Send contents to listeners with the at command of screen
Note: the ending double quote above ensures a ^M to be sent (Cr).
You may enable / disable multicast based on window title this way.