Created
July 21, 2017 16:02
-
-
Save akamiya/b553a592bb035a0c097628d3791d5027 to your computer and use it in GitHub Desktop.
a script to ssh multiple servers over multiple tmux panes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ssh-multi-ec2 | |
# based on ssh-multi by D.Kovalov | |
# https://gist.github.com/dmytro/3984680 | |
# in turn 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 | |
# customized for ec2 | |
starttmux() { | |
if [ -z "$HOSTS" ]; then | |
echo -n "Please provide of list of hosts separated by spaces [ENTER]: " | |
read HOSTS | |
fi | |
local hosts=( $HOSTS ) | |
local ident="" | |
local user="" | |
if [ $IDENT = "none" ]; then | |
ident="" | |
else | |
ident=" -i $IDENT" | |
fi | |
if [ $USER = "none" ]; then | |
user="" | |
else | |
user=" ${USER}@" | |
fi | |
tmux new-window "ssh $ident $user${hosts[0]}" | |
unset hosts[0]; | |
for i in "${hosts[@]}"; do | |
tmux split-window -h "ssh $ident $user$i" | |
tmux select-layout tiled > /dev/null | |
done | |
tmux select-pane -t 0 | |
tmux set-window-option synchronize-panes on > /dev/null | |
} | |
HOSTTMP="${@:3}" | |
HOSTS=${HOSTS:=$HOSTTMP} | |
IDENT=$1 | |
USER=$2 | |
starttmux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment