Reputation: 409
I have an AWS RDS process that generates 4 different output as Creating, Modifying,Backing-up and Available. This output of the process changes every 4 to 5 minutes and finally when the process completes it generates last output as available. Which is am storing in a variable "dbState". What I am trying to do is run a spinner until the variable has the available value. For this, I will have to run two loops 1st one that keeps checking the value of the variable. 2nd one which keeps running the loop and spinner until the variable value becomes available.
while :; do
dbState=(`aws rds describe-db-instances --db-instance-identifier $Instance_Identifier --query DBInstances[*].DBInstanceStatus --output text`)
sp='/-\|'
printf ' '
sleep 0.1
while [ "$dbState" != "available" ]; do
printf '\b%.1s' "Please wait.....$sp"
sp=${sp#?}${sp%???}
sleep 0.1
done
sleep 120
done
But for some reason it gets stuck in the 2nd loop and spinner keeps running even until the vale of variable becomes available. Please help me here i can not think of any logic to achieve that. All i want to to show spinner until the variable vale becomes available.
Upvotes: 1
Views: 205
Reputation: 200850
First, let's focus on the inner loop:
while [ "dbState" != "available" ]; do
printf '\b%.1s' "Please wait.....$sp"
sp=${sp#?}${sp%???}
sleep 0.1
done
Notice how dbState is never updated inside this loop? So there is never an exit condition from the loop. You would have to check the RDS instance state inside each iteration of the loop, so you probably only need the outer loop, and to convert the inner loop into an if
statement.
Further, you have a typo in your condition. You are comparing the literal string "dbState"
to the string "available"
. I believe you want to compare the value of the dbState
variable, which would be: "$dbState" != "available"
.
Note that the AWS CLI Tool already has a method for waiting until an RDS instance state is "available"
:
aws rds wait db-instance-available --db-instance-identifier $Instance_Identifier
Upvotes: 3