Skip to content

Instantly share code, notes, and snippets.

@threetreeslight
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save threetreeslight/5dfba4c307496d546c44 to your computer and use it in GitHub Desktop.
Save threetreeslight/5dfba4c307496d546c44 to your computer and use it in GitHub Desktop.
ec2-ip, ec2-ssh
# ec2-ip
function ec2-ip() {
if [[ $1 == "" ]]; then
PERCOL=percol
else
PERCOL="percol --query $1"
fi
instances | eval $PERCOL | awk '{ print $1 }'
}
function instances() {
instances=( $(aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value[],PublicIpAddress]' \
--output text | awk '{ print $0}') )
for i in `seq 1 ${#instances[@]}`; do
if [ `expr $i % 2` -eq 0 ]; then
echo ${instances[$i-1]} ${instances[$i]}
fi
done
}
# ec2-ssh
function ec2-ssh() {
if [[ $1 =~ "^-" ]]; then
QUERY="" # options only
else
QUERY=$1 # with a query
[[ $# > 0 ]] && shift
fi
ssh webadmin@$(ec2-ip $QUERY) -p2222 -i ~/.ssh/id_rsa
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment