由 Tmux 提供支持的终极终端分屏器!
虽然我们已经可以使用 tmux 进行屏幕的分割和切换,但是如果需要对一批服务器进行操作的话,就只能一个一个的登录和执行了。如果使用过 Xshell 或者其他远程工具的话,肯定是使用过这个功能特性的,一次命令输出可以在登录的多个远程终端上面执行。现在我们可以使用 tmux-xpanes 来完成同样的事情了,撒花!
the features about xpanes
requirements: bash3.2+ and tmux1.8+
- $ brew install tmux-xpanes
- $ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm --eval %rhel).noarch.rpm
- $ sudo yum install xpanes
- $ sudo apt install software-properties-common
- $ sudo add-apt-repository ppa:greymd/tmux-xpanes
- $ sudo apt update
- $ sudo apt install tmux-xpanes
- # Download with wget
- $ wget https://raw.githubusercontent.com/greymd/tmux-xpanes/v4.1.3/bin/xpanes -O ./xpanes
- # Put it under PATH and make it executable.
- $ sudo install -m 0755 xpanes /usr/local/bin/xpanes
- # Clone the repository
- $ git clone https://github.com/greymd/tmux-xpanes.git /path/to/tmux-xpanes
- # ~/.zshrc.
- $ source /path/to/tmux-xpanes/completion.zsh
tmux-xpanes is alias of xpanes
- Usage:
- xpanes [OPTIONS] [argument ...]
- Usage(Pipe mode):
- command ... | xpanes [OPTIONS] [
...] - OPTIONS:
- -h,--help Display this help and exit.
- -V,--version Output version information and exit.
- -B
Run before processing in each pane. Multiple options are allowed. - -c
Set to be executed in each pane. Default is `echo {}`. - -d,--desync Make synchronize-panes option off in new window.
- -e Execute given arguments as is. Same as -c '{}'
- -I
Replacing one or more occurrences of in command provided by -c or -B. Default is `{}`. - -C NUM,--cols=NUM Number of columns of window layout.
- -R NUM,--rows=NUM Number of rows of window layout.
- -l
Set the preset of window layout. Recognized layout arguments are: - t tiled
- eh even-horizontal
- ev even-vertical
- mh main-horizontal
- mv main-vertical
- -n
Set the maximum number of taken for each pane. - -s Speedy mode: Run command without opening an interactive shell.
- -ss Speedy mode AND close a pane automatically at the same time as process exiting.
- -S
Set a full alternative path to the server socket. - -t Display each argument on the each pane is border as their title.
- -x Create extra panes in the current active window.
- --log[=
] Enable logging and store log files to ~/.cache/xpanes/logs or . - --log-format=
Make name of log files follow . Default is `[:ARG:].log.%Y-%m-%d_%H-%M-%S`. - --ssh Same as `-t -s -c 'ssh -o StrictHostKeyChecking=no {}'`.
- --stay Do not switch to new window.
- --bulk-cols=NUM1[,NUM2 ...] Set number of columns on multiple rows (i.e, "2,2,2" represents 2 cols x 3 rows).
- --debug Print debug message.
介绍 xpanes 工具的使用方式和简单工作模式!
编号 参数 含义解释
编号 | 参数 | 含义解释 |
---|---|---|
1 | -d |
打开的窗口不同步输出命令 |
2 | -c |
包含需要执行的命令 |
3 | -I |
用来指定占位符 |
4 | -t |
可以在每个窗格边框上显示每个参数 |
5 | --ssh |
助于忽略 openssh 的警报消息 |
6 | --log |
记录 SSH 连接多个主机并进行日志操作 |
7 | -s |
将不会创建新的交互式 shell 命令 |
8 | -ss |
屏蔽信息 |
9 | -x |
可以在现有窗口上创建新窗格 |
10 | -e |
可以在不同的窗格上执行不同的命令 |
11 | -B |
可以对每个窗格进行预处理 |
12 | -C |
来控制窗口的列 |
13 | -R |
来控制窗口的行 |
14 | --bulk-cols |
指定对应每一行的列数 |
- # 下面两个效果等同
- $ xpanes {1..4}
- $ xpanes 1 2 3 4
- +-------------------------------+-------------------------------+
- │$ echo 1 │$ echo 2 │
- │1 │2 │
- │ │ │
- │ │ │
- +-------------------------------+-------------------------------+
- │$ echo 3 │$ echo 4 │
- │3 │4 │
- │ │ │
- │ │ │
- +-------------------------------+-------------------------------+
- # -d
- $ xpanes -d 1 2 3 4
- # -c
- $ xpanes -c 'seq {}' 1 2 3 4
- +-------------------------------+-------------------------------+
- │$ seq 1 │$ seq 2 │
- │1 │1 │
- │ │2 │
- │ │ │
- │ │ │
- +-------------------------------+-------------------------------+
- │$ seq 3 │$ seq 4 │
- │1 │1 │
- │2 │2 │
- │3 │3 │
- │ │4 │
- │ │ │
- +-------------------------------+-------------------------------+
- # -I
- $ xpanes -I@ -c 'seq @' 1 2 3 4
- # -c
- $ xpanes -c "ssh myuser@{}" host1 host2
- $ xpanes -c "ssh -t {} bash -ci 'll'" host-{1,2,3}
- $ xpanes -c "tail -f {}" /var/log/apache/{error,access}.log /var/log/application/{error,access}.log
- $ xpanes -c "ssh user@host tail -f {}" /var/log/apache/{error,access}.log /var/log/application/{error,access}.log
- # 下面两个效果等同
- $ xpanes --ssh myuser1@host1 myuser2@host2
- $ xpanes -t -s -c "ssh -o StrictHostKeyChecking=no {}" myuser1@host1 myuser2@host2
- $ xpanes --log=~/operation_log -c "ssh {}" user1@host1 user2@host2
- +-------------------------------+-------------------------------+
- │$ ssh user1@host1 │ $ ssh user2@host2 │
- │ │ │
- │ │ │
- │ │ │
- │ │ │
- +-------------------------------+-------------------------------+
- $ ls ~/operation_log/
- user1@host1-1.log.2017-03-15_21-30-07
- user2@host2-1.log.2017-03-15_21-30-07
- $ xpanes -s -c "seq {}" 2 3 4 5
- +------------------------------------------+------------------------------------------+
- │1 │1 │
- │2 │2 │
- │Pane is dead: Press [Enter] to exit... │3 │
- │ │Pane is dead: Press [Enter] to exit... │
- │ │ │
- │ │ │
- │ │ │
- +------------------------------------------+------------------------------------------+
- │1 │1 │
- │2 │2 │
- │3 │3 │
- │4 │4 │
- │Pane is dead: Press [Enter] to exit... │5 │
- │ │Pane is dead: Press [Enter] to exit... │
- │ │ │
- │ │ │
- +------------------------------------------+------------------------------------------+
- # 屏蔽信息
- $ xpanes -ss -c "seq {}" 2 3 4 5
- # 标题
- $ xpanes -t -c "ping {}" 192.168.1.{5..8}
- +------------------------------------------+------------------------------------------+
- │ping 192.168.1.5 │ping 192.168.1.6 │
- │ │ │
- │ │ │
- │ │ │
- │ │ │
- +---192.168.1.5----------------------------+---192.168.1.6----------------------------+
- │ping 192.168.1.7 │ping 192.168.1.8 │
- │ │ │
- │ │ │
- │ │ │
- │ │ │
- +---192.168.1.7----------------------------+---192.168.1.8----------------------------+
- # before
- +-------------------------------+-------------------------------+
- │$ │$ │
- │ │ │
- │ │ │
- │ │ │
- +-------------------------------+-------------------------------+
- │ $ xpanes -x 4 5 6 │
- │ │
- │ │
- │ │
- +-------------------------------+-------------------------------+
- # after
- +-------------------------------+-------------------------------+
- │$ │$ │
- │ │ │
- │ │ │
- │ │ │
- +-------------------------------+-------------------------------+
- │$ xpanes -x 4 5 6 │$ echo 4 │
- │$ │4 │
- │ │$ │
- │ │ │
- +-------------------------------+-------------------------------+
- │$ echo 5 │$ echo 6 │
- │5 │6 │
- │$ │$ │
- │ │ │
- +-------------------------------+-------------------------------+
- # 下面两个效果等同
- $ xpanes -e "top" "vmstat 1" "watch -n 1 free"
- $ xpanes -I@ -c "@" "top" "vmstat 1" "watch -n 1 free"
- +-------------------------------+------------------------------+
- │$ top │$ vmstat 1 │
- │ │ │
- │ │ │
- +-------------------------------+------------------------------+
- │$ watch -n 1 free │
- │ │
- │ │
- +--------------------------------------------------------------+
- $ xpanes -B 'echo Preprocessing' -c 'echo Test' _
- +-------------------------------+
- │$ echo Preprocessing │
- │Preprocessing │
- │$ echo Test │
- │Test │
- │ │
- +-------------------------------+
- $ xpanes -B 'echo Pre1' -B 'echo Pre2' -B 'echo Pre3' -c 'echo {}' A B C D
- +-------------------------------+------------------------------+
- │$ echo Pre1 │$ echo Pre1 │
- │Pre1 │Pre1 │
- │$ echo Pre2 │$ echo Pre2 │
- │Pre2 │Pre2 │
- │$ echo Pre3 │$ echo Pre3 │
- │Pre3 │Pre3 │
- │$ echo A │$ echo B │
- +-------------------------------+------------------------------+
- │$ echo Pre1 │$ echo Pre1 │
- │Pre1 │Pre1 │
- │$ echo Pre2 │$ echo Pre2 │
- │Pre2 │Pre2 │
- │$ echo Pre3 │$ echo Pre3 │
- │Pre3 │Pre3 │
- │$ echo C │$ echo D │
- +-------------------------------+------------------------------+
- $ xpanes -C 2 AAA BBB CCC DDD
- +------------------------------+------------------------------+
- │$ echo AAA │$ echo BBB │
- │ │ │
- │ │ │
- +------------------------------+------------------------------+
- │$ echo CCC │$ echo DDD │
- │ │ │
- │ │ │
- +------------------------------+------------------------------+
- $ xpanes -R 5 AAA BBB CCC DDD EEE FFF GGG HHH
- +------------------------------+------------------------------+
- │$ echo AAA │$ echo BBB │
- │ │ │
- +------------------------------+------------------------------+
- │$ echo CCC │$ echo DDD │
- │ │ │
- +------------------------------+------------------------------+
- │$ echo EEE │$ echo FFF │
- │ │ │
- +------------------------------+------------------------------+
- │$ echo GGG │
- │ │
- +-------------------------------------------------------------+
- │$ echo HHH │
- │ │
- +-------------------------------------------------------------+
- $ xpanes --bulk-cols=1,3,1,2,5 {A..L}
- +-------------------------------------------------------------+
- │$ echo A │
- │ │
- +-------------------------------------------------------------+
- │$ echo B │$ echo C │$ echo D │
- │ │ │ │
- +-------------------------------------------------------------+
- │$ echo E │
- │ │
- +-------------------------------------------------------------+
- │$ echo F │$ echo G │
- │ │ │
- +-------------------------------------------------------------+
- │$ echo H │$ echo I │$ echo J │$ echo K │$ echo L │
- │ │ │ │ │ │
- +-------------------------------------------------------------+
- $ seq 3 | xpanes
- +------------------------------+------------------------------+
- │$ echo 1 │$ echo 2 │
- │1 │2 │
- │ │ │
- │ │ │
- +------------------------------+------------------------------+
- │$ echo 3 │
- │3 │
- │ │
- │ │
- +------------------------------+------------------------------+
- $ seq 4 | xpanes seq
- $ seq 4 | xpanes -c 'seq {}'
- $ cat ~/.ssh/config | awk '$1=="Host"{print $2}' | xpanes ssh
- # 默认情况会创建:~/.cache/xpanes/socket.
- $ ls ~/.cache/xpanes/socket.*
- /home/user/.cache/xpanes/socket.1234
- # 会话恢复
- $ tmux -S /home/user/.cache/xpanes/socket.1234 attach
- # 与他人共享终端会话 - user1
- [user1@host] $ xpanes -S /home/user1/mysocket a b c d ...
- # 与他人共享终端会话 - user2
- [user2@host] $ tmux -S /home/user1/mysocket attach
Let’s play!
- $ yes terminal-parrot | head -n 25 | xpanes -e
- $ yes 'sl -l' | head | xpanes -elev
- github tmux-xpanes
下一篇:带你了解Vue 3.0 七大亮点