Skip to content

Instantly share code, notes, and snippets.

@serkanh
Last active October 13, 2018 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save serkanh/64c91898187e2ab03ae9cdc5e1d81114 to your computer and use it in GitHub Desktop.
Save serkanh/64c91898187e2ab03ae9cdc5e1d81114 to your computer and use it in GitHub Desktop.
to get decoded user data from ec2 instances
#/bin/bash
trap exit INT
INSTANCES=$( aws --profile=HA ec2 describe-instances --query 'Reservations[].Instances[].InstanceId[]' | sed -e 's/\[//g' -e 's/\]//g')
SUM=0
echo $INSTANCES
for i in $( echo $INSTANCES | sed -e 's/"//g' -e 's/,//g' -e 's/\[//g' -e 's/\]//g' ) ;do
echo "---------------------------$i-------------------------------\n"
aws --profile=HA ec2 describe-instances --instance-ids $i --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value' --output text
aws --profile=HA ec2 describe-instance-attribute --instance-id $( echo $i | sed -e 's/"//g' -e 's/,//' -e 's/\[//g' -e 's/\]//g' ) --attribute userData \
| jq '.UserData.Value' | sed 's/"//g' | base64 --decode
((SUM += 1))
echo "\n"
done
echo "Total Number of Servers: $SUM"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment