-
-
Save 10long/4146a14f3711bfa1a2cec731db5d5c9e 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
#export AWS_ACCESS_KEY_ID="AWSのアクセスキー" | |
#export AWS_SECRET_ACCESS_KEY="AWSのシークレットアクセスキー" | |
use nix |
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
with import <nixpkgs> {}; { | |
shellEnv = stdenv.mkDerivation { | |
name = "shell-env"; | |
buildInputs = [ | |
awscli | |
jq | |
]; | |
}; | |
} |
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 | |
# 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