Last active
October 13, 2018 23:20
-
-
Save serkanh/64c91898187e2ab03ae9cdc5e1d81114 to your computer and use it in GitHub Desktop.
to get decoded user data from ec2 instances
This file contains hidden or 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 | |
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