Created
February 23, 2012 11:20
-
-
Save nickpeirson/1892436 to your computer and use it in GitHub Desktop.
Quick bash script for cleaning up ec2 instances and associated opscode node/client. Accepts partial/full instance name as an argument.
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 | |
INSTANCE="$1" | |
if [ "x$INSTANCE" = "x" ]; then | |
echo "Please specify an instance" | |
exit 1 | |
fi | |
INSTANCE=$(knife ec2 server list | awk "/$INSTANCE/{ print \$1 }") | |
if [ "x$INSTANCE" = "x" ]; then | |
echo 'Instance not found' | |
exit 2 | |
fi | |
echo -n "Are you sure you want to delete $INSTANCE? [y/n] " | |
read DELETE | |
DELETE=$(echo $DELETE | tr '[A-Z]' '[a-z]') | |
if [ "$DELETE" != "y" ]; then | |
echo "Not deleting" | |
exit 0 | |
fi | |
yes | knife ec2 server delete "$INSTANCE" && yes | knife node delete "$INSTANCE" && yes | knife client delete "$INSTANCE" && echo "Instance deleted" && exit 0 | |
echo "Couldn't delete instance and/or clean up opscode client and node" | |
exit 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment