Created
October 1, 2012 19:02
-
-
Save andsens/3813743 to your computer and use it in GitHub Desktop.
Starts a single instance and measures the time until SSH connectivity
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 -e | |
# These need to be set. | |
#export EC2_HOME="/path/to/ec2-api-tools" | |
#export AWS_ACCESS_KEY='XXXXXXXXXXXXXXXXXXXX' | |
#export AWS_SECRET_KEY='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
#export PATH="$PATH:${EC2_HOME}/bin" | |
ami_id='ami-123abc12' | |
availability_zone='eu-west-1a' | |
keypair="[email protected]" | |
instance_type="t1.micro" | |
start_time=`date +%s` | |
instance_id=`ec2-run-instances "$ami_id" \ | |
--availability-zone "$availability_zone" \ | |
--instance-type "$instance_type" \ | |
--key "$keypair" \ | |
| grep 'INSTANCE' | awk '{print $2}'` | |
printf "Instance ID: %s\n" "$instance_id" | |
sleep 5 | |
while [ 1 ]; do | |
instance_uri=`ec2-describe-instances --filter "instance-id=$instance_id" | grep "INSTANCE" | awk '{print $4}'` | |
if [[ -n "$instance_uri" && "$instance_uri" != 'pending' ]]; then | |
break | |
fi | |
sleep 1 | |
done | |
if [[ ! "$instance_uri" =~ "compute.amazonaws.com" ]]; then | |
printf "'$instance_uri' does not look like an instance URI\n" | |
exit 1 | |
fi | |
printf "Instance URI: %s\n" "$instance_uri" | |
ssh_cmd="ssh root@$instance_uri -o StrictHostKeyChecking=no -o ConnectTimeout=1 echo 'test' 2>/dev/null || true" | |
while [ -z "$cmd_status" ]; do | |
printf '.' | |
sleep 1 | |
cmd_status=`eval $ssh_cmd` | |
done | |
end_time=`date +%s` | |
ec2-terminate-instances "$instance_id" > /dev/null | |
bootup_time="$(($end_time - $start_time))" | |
printf "Bootup Time: %i seconds\n" "$bootup_time" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment