Skip to content

Instantly share code, notes, and snippets.

@oldpatricka
Created January 20, 2012 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldpatricka/1648969 to your computer and use it in GitHub Desktop.
Save oldpatricka/1648969 to your computer and use it in GitHub Desktop.
A script to remind you if you've left instances running
#!/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