Artificial intelligent assistant

How to do infinite loop using do while and break if something failed? I'm trying to check the status of AWS AMI and execute some commands if the status is `available`. Below is my small script to achieve that. #!/usr/bin/env bash REGION="us-east-1" US_EAST_AMI="ami-0130c3a072f3832ff" while : do AMI_STATE=$(aws ec2 describe-images --region "$REGION" --image-ids $US_EAST_AMI | jq -r .Images[].State) [ "$AMI_STATE" == "available" ] && echo "Now the AMI is available in the $REGION region" && break sleep 10 done The above script works fine if the first call was a success. But I'm expecting something for the below scenarios * If the value of the `$AMI_STATE` is equal to `"available"`(currently working), `"failed"` it should break the loop * If the value of the `$AMI_STATE` is equal to `"pending"`, the loop should continue until it meets the expected value.

You want to run the loop while the value of `AMI_STATE` is equal to `pending`… so write just that.


while
AMI_STATE=$(aws ec2 describe-images --region "$REGION" --image-ids $US_EAST_AMI | jq -r .Images[].State) &&
[ "$AMI_STATE" = "pending" ]
do
sleep 10
done
case $AMI_STATE in
"") echo "Something went wrong: unable to retrieve AMI state";;
available) echo "Now the AMI is available in the $REGION region";;
failed) echo "The AMI has failed";;
*) echo "AMI in weird state: $AMI_STATE";;
esac

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2f81b4c2f9c5fca52d256574ebf54a8d