Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active July 31, 2016 04:34
Show Gist options
  • Save greymd/7d718197c9e296ee99454a06c7e89754 to your computer and use it in GitHub Desktop.
Save greymd/7d718197c9e296ee99454a06c7e89754 to your computer and use it in GitHub Desktop.
Multiple ssh session (It works even the current terminal is already in tmux)
#!/bin/bash
# ****MOVE TO*** https://github.com/greymd/tmssh
# ssh-multi
# yasuhiro.yamada
# Based on http://linuxpixies.blogspot.jp/2011/06/tmux-copy-mode-and-how-to-control.html
# and https://gist.github.com/dmytro/3984680
# 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 -n "$WIN_NAME"
for i in "${hosts[@]}"; do
tmux split-window -t "$WIN_NAME" -h "ssh $i"
done
tmux kill-pane -t "${WIN_NAME}.0"
tmux select-pane -t "${WIN_NAME}.0"
tmux select-layout -t "${WIN_NAME}" tiled > /dev/null
tmux set-window-option -t "${WIN_NAME}" synchronize-panes on > /dev/null
}
WIN_NAME="$1-$$"
HOSTS=${HOSTS:=$*}
starttmux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment