Created
January 20, 2012 18:50
-
-
Save oldpatricka/1648969 to your computer and use it in GitHub Desktop.
A script to remind you if you've left instances running
This file contains 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 | |
# | |
# mail-ec2-report.bash - A script to remind you if you've left instances running | |
# You must set this: | |
EMAIL="foo@example.com" # email address (or list of email addresses) to send message to | |
# You may want to set these: | |
#REGIONS="" # By default, generates a report for every region | |
#MAIL="mail" # Mail program to use. Maybe try: https://github.com/oldpatricka/maul | |
## End of config options | |
if [ -z "$REGIONS" ]; then | |
REGIONS=`ec2-describe-regions | awk '{print $2}'` | |
fi | |
if [ -z "$MAIL" ]; then | |
MAIL="mail" | |
fi | |
message="" | |
for REGION in $REGIONS ; do | |
instances=`ec2-describe-instances --region ${REGION} | grep INSTANCE | wc -l` | |
if [[ $instances -gt 0 ]]; then | |
message="${REGION}: ${instances} running\n${message}" | |
fi | |
done | |
if [ -n "$message" ]; then | |
printf "$message" | $MAIL -s "Instances running on EC2" $EMAIL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment