Skip to content

Instantly share code, notes, and snippets.

@iuriaranda
Created January 15, 2012 22:28
Show Gist options
  • Select an option

  • Save iuriaranda/1617746 to your computer and use it in GitHub Desktop.

Select an option

Save iuriaranda/1617746 to your computer and use it in GitHub Desktop.
Script to delete unattached EBS volumes on Amazon EC2
#!/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