Created
October 31, 2013 03:42
-
-
Save dialtone/7244094 to your computer and use it in GitHub Desktop.
Given a few parameters connect to a set of ec2 instances, one per tmux pane
This file contains hidden or 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_KEY= | |
USERNAME= | |
usage() { echo "Usage: $0 -s <tmux_session_name> [-k <my_ssh_key.pem>] [-u <username>] <host> <host1> ..." 1>&2; exit 1; } | |
while getopts "s:k:u:" option; | |
do | |
case "${option}" in | |
s) SESSION_NAME=${OPTARG};; | |
k) SSH_KEY=${OPTARG};; | |
u) USERNAME=${OPTARG};; | |
*) usage;; | |
esac | |
done | |
if [[ "$SESSION_NAME" == "" ]]; then | |
usage | |
fi | |
if [[ "$SSH_KEY" == "" ]]; then | |
SSH_KEY_PART= | |
else | |
SSH_KEY_PART="-i $SSH_KEY" | |
fi | |
if [[ "$USERNAME" == "" ]]; then | |
USERNAME_PART= | |
else | |
USERNAME_PART="$USERNAME@" | |
fi | |
shift $((OPTIND-1)) | |
HOSTS=($@) | |
tmux new -d -s $SESSION_NAME | |
for index in ${!HOSTS[*]} | |
do | |
if [[ "$index" == "0" ]]; then | |
continue | |
fi | |
tmux split-window -t $SESSION_NAME.0 -h | |
done | |
tmux select-layout -t $SESSION_NAME even-horizontal | |
for index in ${!HOSTS[*]} | |
do | |
host=${HOSTS[$index]} | |
tmux send -l -t $SESSION_NAME.$index "ssh $SSH_KEY_PART $USERNAME_PART$host" | |
done | |
tmux attach -t $SESSION_NAME | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment