Skip to content

Instantly share code, notes, and snippets.

@komazarari
Last active October 24, 2016 01:34
Show Gist options
  • Save komazarari/7fc908257d24faf2997344c25e7163f5 to your computer and use it in GitHub Desktop.
Save komazarari/7fc908257d24faf2997344c25e7163f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
if uname | grep Darwin > /dev/null; then
BSD=true
else
BSD=false
fi
if $BSD; then
DATE_B2D=$(date -u -v-2d +"%Y-%m-%dT00:00:00")
DATE_B1D=$(date -u -v-1d +"%Y-%m-%dT00:00:00")
SHA1="openssl sha1"
else
DATE_B2D=$(date -u -d "2 day ago" +%Y-%m-%dT00:00:00)
DATE_B1D=$(date -u -d "1 day ago" +%Y-%m-%dT00:00:00)
SHA1="sha1sum"
fi
describe_regions() {
aws ec2 describe-regions --region ap-northeast-1 --query 'Regions[].RegionName' --output text | sed -e 's/[[:blank:]]/,/g' | tr ',' '\n'
}
describe_spot_price_history() {
local region=$1
# for az in a b c d; do
for az in a c; do
local history=$(aws ec2 describe-spot-price-history --region $region \
--start-time $DATE_B2D --end-time $DATE_B1D \
--availability-zone $region$az --output text 2> /dev/null \
| sed -e "s/$region$az//" | sort)
if [[ -n $history ]]; then
echo "$region$az $($SHA1<<<"$history")"
fi
done
}
#describe_regions | while read r
echo ap-northeast-1 | while read r
do
describe_spot_price_history $r
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment