Skip to content

Instantly share code, notes, and snippets.

@Kgirthofer
Created April 19, 2016 19:35
Show Gist options
  • Save Kgirthofer/c9d58dac57d610cc29023e93eb507694 to your computer and use it in GitHub Desktop.
Save Kgirthofer/c9d58dac57d610cc29023e93eb507694 to your computer and use it in GitHub Desktop.
#!/bin/bash
arr=($(aws ec2 describe-instances --filters "Name=tag-key,Values=Purge" --output table | grep InstanceId | awk '{print $4}'))
for index in "${!arr[@]}"
do
purge_time=$(aws ec2 describe-instances --instance-ids ${!arr[index]})
if $purge_time = 24h; then
printf "got one"
fi
printf "deleting server %s\n" ${arr[index]}
aws ec2 terminate-instances --instance-ids ${arr[index]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment