Skip to content

Instantly share code, notes, and snippets.

@cbweixin
Created August 13, 2015 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbweixin/30600323228891d28580 to your computer and use it in GitHub Desktop.
Save cbweixin/30600323228891d28580 to your computer and use it in GitHub Desktop.
aws remove all in-active volumes
#!/bin/bash
ids=$(aws ec2 describe-volumes --output=json --query 'Volumes[?State!=`in-use`].VolumeId')
arr=()
read -a arr <<< $(echo "$ids"| jq '.[]')
for id in "${arr[@]}"; do
#remove the suffix double quotes
id="${id%\"}"
#remove the prefix double quotes
id="${id#\"}"
#aws ec2 delete-volume --volume-id "$id"
echo "$id"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment