xiringuito/discover-routes.aws.example
2018-01-29 18:49:55 +01:00

19 lines
664 B
Bash
Executable File

#!/usr/bin/env bash
#
# Route discovery primer for AWS
#
if [[ ${#} != 1 ]]; then
echo "Usage: ${0} SSH_SERVER"
exit 1
fi
export AWS_PROFILE=$(echo ${1} | awk -F"." '{print $2}')
VPC_URL='http://169.254.169.254/latest/meta-data/network/interfaces/macs/$(/sbin/ip link show dev eth0 | grep link/ether | awk '"'"'{print $2}'"'"')/vpc-id'
VPC_ID=$(ssh ${SSH_PRIVATE_KEY_OPTS} ${SSH_PORT_OPTS} ${SSH_EXTRA_OPTS} ${1} curl -s \"${VPC_URL}\")
if [[ ${?} -eq 0 && -n "${VPC_ID}" ]]; then
FILTER_PARAMS="--filters Name=vpc-id,Values=${VPC_ID}"
fi
aws ec2 describe-subnets ${FILTER_PARAMS} | grep CidrBlock\":\ \"10 | awk -F"\"" '{print "ROUTE:"$4}' | sort | uniq