Created
July 7, 2016 05:02
-
-
Save alangarf/d1613db5228f217a0f99b349d9ce7d02 to your computer and use it in GitHub Desktop.
SSHs to an AWS instance with an ASG hostname
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 | |
IFS=$'\n' | |
unsorted_hosts=($(aws ec2 describe-instances --query "Reservations[].Instances[].{Name:Tags[?Key=='Name'].Value|[0]}" --output text --filters "Name=tag:Name,Values=*$1*")) | |
hosts=($(sort -V <<<"${unsorted_hosts[*]}")) | |
unset IFS | |
len=$(expr ${#hosts[@]} - 1) | |
for i in $(seq 0 $len); do | |
id=$(expr $i + 1) | |
echo -e "\e[31m[\e[39m$id\e[31m]\e[39m \e[33m${hosts[$i]}\e[39m" | |
done | |
echo -en "\n\e[95mSelect host:\e[39m " | |
read -n 3 input | |
case $input in | |
[1-9]*) | |
input=$(expr $input - 1) | |
ssh "${hosts[$input]}" | |
;; | |
*) | |
exit | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment