Skip to content

Instantly share code, notes, and snippets.

@Aricg
Last active December 16, 2015 23:21
Show Gist options
  • Select an option

  • Save Aricg/5512778 to your computer and use it in GitHub Desktop.

Select an option

Save Aricg/5512778 to your computer and use it in GitHub Desktop.
ec2-describe-instances ec2-describe-volumes and ec2-describe-snapshots for x environments all availability zones. assumes keys are in /home/ubuntu/KEYS/* and names foo.key and foo.pem Also counts size in gigs of attached volumes as well as all snapshots.
#!/bin/bash
for x in $(find /home/ubuntu/KEYS/* -type f | grep ".key");
do
#Get a list of avaliable avaliablility zones
if [[ ! -e tmp_zones ]]; then
ec2-describe-regions -C ${x%.*}.pem -K ${x%.*}.key | awk '{ print $2 }' > tmp_zones
fi
for zone in $(cat tmp_zones)
do
echo "Logging "$(basename ${x%.*})"'s instances in $zone avaliablity zone"
ec2-describe-instances --headers --region "$zone" -K ${x%.*}.key -C ${x%.*}.pem > /home/ubuntu/Inventory/instances-"$zone"-"$(basename ${x%.*})"
echo "Logging "$(basename ${x%.*})"'s volumes in $zone avaliablity zone"
ec2-describe-volumes --headers --region "$zone" -K ${x%.*}.key -C ${x%.*}.pem > /home/ubuntu/Inventory/volumes-"$zone"-"$(basename ${x%.*})"
echo "Logging "$(basename ${x%.*})"'s snapshots in $zone avaliablity zone"
ec2-describe-snapshots --headers --region "$zone" -K ${x%.*}.key -C ${x%.*}.pem > /home/ubuntu/Inventory/snapshots-"$zone"-"$(basename ${x%.*})"
done
done
cd /home/ubuntu/Inventory/
#disk usage all attached volumes (per client)
for x in $(find . -type f | grep volumes | grep eu ); do echo $x; cat $x | grep in-use | awk '{ i = i+$3}; END { print i, "GIGS" }'; done >> /tmp/RUNNINGdiskusage
#disk usage all snapshots (per client)
for x in $(find . -type f | grep snapshot | grep eu ); do echo $x; cat $x | grep SNAPSHOT | awk '{ i=i+$8}; END { print i, "GIGS" }'; done >> /tmp/BACKUPusage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment