Skip to content

Instantly share code, notes, and snippets.

@mhotan
Forked from dmytro/ssh-multi.sh
Last active November 30, 2016 22:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhotan/384f20e6923fa7106635 to your computer and use it in GitHub Desktop.
Save mhotan/384f20e6923fa7106635 to your computer and use it in GitHub Desktop.
Start multiple synchronized SSH connections with Tmux
#!/bin/bash
# ssh-multi
# D.Kovalov
# Based on http://linuxpixies.blogspot.jp/2011/06/tmux-copy-mode-and-how-to-control.html
# a script to ssh multiple servers over multiple tmux panes
starttmux() {
if [ -z "$HOSTS" ]; then
echo -n "Please provide of list of hosts separated by spaces [ENTER]: "
read HOSTS
fi
local hosts=( $HOSTS )
tmux new-window "ssh ${hosts[0]}"
unset hosts[0];
for i in "${hosts[@]}"; do
tmux split-window -h "ssh $i"
tmux select-layout tiled > /dev/null
done
tmux select-pane -t 0
tmux set-window-option synchronize-panes on > /dev/null
}
HOSTS=${HOSTS:=$*}
starttmux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment