I recently found a nice way to work on multiple servers using tmux and OpenSSH (not only, but who uses something else?).
The script looks like this:
if [ $# -gt 0 ]; then
for host in $(egrep '^host' ~/.ssh/config | grep -v '\*' | pcregrep -o "\s+$1\S*?(\s|$)")
STYLE=$(pcregrep -A1 "\s$host(\s|$)" ~/.ssh/config | grep -o 'tmux-style: .*' | cut -d' ' -f2-)
tmux send-keys "ssh $host $2" \; select-pane -P "$STYLE" \; split-window \; select-layout tiled
if [ $OK = "1" ]; then
tmux set-window-option synchronize-panes \; send-keys ENTER
tmux kill-pane \; select-layout tiled
The script reads your ~/.ssh/config file and based on host entries it creates panes in a single tmux window and synchronises inputs to them. This allows for a simultaneous work done on multiple machines.
It also supports for setting styles for different hosts in your ~/.ssh/config file.
Assuming you have a ~/.ssh/config file that looks like this:
# tmux-style: bg=red
# tmux-style: bg=blue
And also assuming that you saved the script in ~/bin/st then running this command:
$ st abc
will spawn to synchronised panes in your current window one with red and one with blue background
if you run:
$ st def-vm
$ st def-
it will spawn five panes to each one of the def-vm machines.
Post a Comment