N P
N P

Reputation: 2619

Check output of bash script

I am using the bash script wait for it to check if a container is up and running before I launch another container.

https://github.com/vishnubob/wait-for-it

It seems that if it's successful it returns 0 and if not 124. Is it possible to check this value and if it's not successful exit the script?

I've tried

./wait-for-it.sh $BROKER_ADDRESS
echo $?
if ($?==124)
    then
    echo "exiting as broker service never became available"
    exit
fi

And I can see it echos 124 in my terminal but then the check fails and it carries on launching the container. I'm assuming my conditional check is wrong but I can't seem to figure out why

Upvotes: 1

Views: 77

Answers (1)

user2700022
user2700022

Reputation: 509

$? Always returns the exit status of the previous command so in this case in your 3rd line in if loop you are comparing exit status of the echo command in your second line to 124. So either remove the second line or store the exit status to a variable & use that variable in your if loop.

Upvotes: 1

Related Questions