Skip to content

Instantly share code, notes, and snippets.

@groundwater
Last active December 21, 2015 11:39
Show Gist options
  • Save groundwater/6300829 to your computer and use it in GitHub Desktop.
Save groundwater/6300829 to your computer and use it in GitHub Desktop.
#!/bin/bash
REGION="-region us-west-2"
if [ -z "$1" ]
then
as-describe-auto-scaling-instances ${REGION}
exit 0
fi
echo "Looking Up Host $1"
INSTANCEID=$(as-describe-auto-scaling-instances ${REGION} | grep $1 | head -n1 | awk '{print $2}')
if [ -z "${INSTANCEID}" ]
then
echo "Instance $1 Not Found"
exit -1
else
echo Found Instance ID ${INSTANCEID}
fi
INSTANCE=$(ec2-describe-instances $INSTANCEID --show-empty-fields ${REGION} | grep INSTANCE )
IP=$(echo ${INSTANCE} | awk '{print $18}')
echo "Connecting to Host ${IP}"
exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${IP}

Usage: asg-connect DESCRIPTION

The asg-connect command will search for Auto-Scale Group instances that match the description. The first instances will be selected and you will be SSH'd into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment