Skip to content

Instantly share code, notes, and snippets.

@10long
Forked from akamiya/ssh-multi-ec2
Created July 24, 2017 01:36
Show Gist options
  • Save 10long/4146a14f3711bfa1a2cec731db5d5c9e to your computer and use it in GitHub Desktop.
Save 10long/4146a14f3711bfa1a2cec731db5d5c9e to your computer and use it in GitHub Desktop.
a script to ssh multiple servers over multiple tmux panes
#export AWS_ACCESS_KEY_ID="AWSのアクセスキー"
#export AWS_SECRET_ACCESS_KEY="AWSのシークレットアクセスキー"
use nix
with import <nixpkgs> {}; {
shellEnv = stdenv.mkDerivation {
name = "shell-env";
buildInputs = [
awscli
jq
];
};
}
#!/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
# dependency lib [awscli,jq]
# 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
hosts=($(aws ec2 describe-instances | jq '.Reservations[].Instances[].PublicDnsName'))
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 "ssh $ident $user$i"
tmux select-layout tiled > /dev/null
done
}
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