Created
January 15, 2012 22:28
-
-
Save iuriaranda/1617746 to your computer and use it in GitHub Desktop.
Script to delete unattached EBS volumes on Amazon EC2
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/sh | |
| y=false | |
| while getopts "y" OPTION | |
| do | |
| case $OPTION in | |
| y) | |
| y=true | |
| ;; | |
| ?) | |
| exit | |
| ;; | |
| esac | |
| done | |
| for v in $(ec2-describe-volumes | grep VOLUME | grep available | awk '{print $2}'); do | |
| if [ "$y" != "true" ]; then | |
| echo "Available volume found $v . Delete? [Nya]" | |
| read opt | |
| if [ "$opt" == "a" ]; then | |
| y=true | |
| opt=y | |
| fi | |
| else | |
| opt=y | |
| fi | |
| if [ "$opt" == "y" -o "$opt" == "Y" -o "$opt" == "yes" ]; then | |
| echo "Deleting $v"; | |
| ec2-delete-volume $v | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment