START_TIME=`date +%s` NEW_INSTANCE_ID=`${AWSCMD} ec2 run-instances --image-id ${IMAGE_NAME} --instance-type ${INSTANCETYPE} --key-name ${KEYNAME} --security-group-ids ${SECURITYGROUPS} --subnet-id ${SUBNETID} --placement ${PLACEMENT} | egrep "^INSTANCES" | awk -F'\t' '{print $8}'` RUNNING_STATE="wait" while [ "${RUNNING_STATE}" = "wait" ]; do RUNNING_ELASPED=`date +%s` ELASPED_DIFF=`echo "${RUNNING_ELASPED} - ${START_TIME}" | bc` sleep 5 DESCRIBE_INSTANCE_STATUS=`${AWSCMD} ec2 describe-instance-status --instance-ids ${NEW_INSTANCE_ID}` if [ `echo "${DESCRIBE_INSTANCE_STATUS}" | egrep "^INSTANCESTATE" | grep "running" | wc -l` -ge 1 ] \ && [ `echo "${DESCRIBE_INSTANCE_STATUS}" | egrep "^INSTANCESTATUS" | grep "ok" | wc -l` -ge 1 ] \ && [ `echo "${DESCRIBE_INSTANCE_STATUS}" | egrep "^SYSTEMSTATUS" | grep "ok" | wc -l` -ge 1 ] \ && [ `echo "${DESCRIBE_INSTANCE_STATUS}" | egrep "^DETAILS" | wc -l` -eq `echo "${DESCRIBE_INSTANCE_STATUS}" | egrep "^DETAILS" | grep "passed" | wc -l` ]; then RUNNING_STATE=running elif [ ${ELASPED_DIFF} -gt ${TIMEOUT} ]; then echo timeout exit 1 fi echo ${ELASPED_DIFF} seconds for launching ${NEW_INSTANCE_ID} done