Created
May 5, 2015 00:35
-
-
Save mblakele/fb9f5327f1e115ae129a to your computer and use it in GitHub Desktop.
check termination status on all my ec2 instances
This file contains 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/bash | |
# | |
set -e | |
# It seems to be important to keep each json dict small enough for one line. | |
for o in $(aws ec2 describe-instances | jq '.Reservations[].Instances[]' \ | |
| jq -c '{ InstanceId, Tags }'); do | |
id=$(echo $o | jq -e -r '.InstanceId') | |
name=$(echo $o | jq -e -r '.Tags[]|select(.Key == "Name").Value') | |
# No -e because false triggers it. | |
term=$(aws ec2 describe-instance-attribute --instance-id $id \ | |
--attribute disableApiTermination \ | |
| jq -r '.DisableApiTermination.Value') | |
echo $term $name $id; | |
done | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment