Many simple mistakes in your original code: While
not while
, missing spaces around [
, missing double-quotes, comparision operators -eq
and -ne
are not for comparing strings...
Beware using wait
, which is a valid shell command. But probably you meant sleep
instead. Here details about the differences.
Try this:
while [ "$INSTANCE_STATUS" = "available" ]
do
sleep 15 # 'waits' 15 seconds.
# ATTENTION: here you might need to 'refresh' $INSTANCE_STATUS value to avoid an endless loop.
# Solution suggested by @Charles Duffy:
# INSTANCE_STATUS=$(systemctl status "$SOURCE_INSTANCE_ID")
if [ "$INSTANCE_STATUS" != "available" ]
then
echo "$SOURCE_INSTANCE_ID is $INSTANCE_STATUS"
fi
done
Edited: many fixes to original answer suggested ...forced ;) by @Charles Duffy. Thanks Charles, now I realize my shell script skills are getting pretty rusty.