Created
August 9, 2013 17:52
-
-
Save danman01/6195621 to your computer and use it in GitHub Desktop.
toggle your staging amazon ec2 instance when you run the script
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 | |
# make sure to have amazon ec2 command line tools installed | |
# this script assumes have an elastic ip, and the instance id is static | |
# enter your settings here | |
STAGING="instance-id" | |
STAGING_IP="your elastic ip" | |
# get the status if your instance | |
STATUS=`ec2-describe-instances $STAGING | awk 'FNR == 2 {print $6}'` | |
echo 'STATUS =' $STATUS | |
# start or stop depending on the status returned | |
if [ $STATUS == "running" ]; then | |
echo "instance is currently running" | |
echo -n "Enter stop or exit > " | |
read text | |
if [ $text == "stop" ]; then | |
echo "stopping instance $STAGING" | |
ec2-stop-instances $STAGING | |
else | |
exit | |
fi | |
else | |
if [ $STATUS == "stopping" ]; then | |
echo "instance is stopping. exiting script" | |
exit | |
fi | |
if [ $STATUS == "0" ]; then | |
# status moved to column 4. column 6 is 0 | |
echo "starting instance $STAGING" | |
ec2-start-instances $STAGING | |
echo "assigning ip $STAGING_IP" | |
sleep 15 | |
ec2-associate-address -i $STAGING $STAGING_IP | |
echo "instance is already running" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment