vmwgeek
vmwgeek

Reputation: 87

Shell script to poll whether a service is up

I wanted to know if there is any error in the code

while true
do
    var=$(curl http://${SERVER_HOST}:8060/vmc/vdisizer/api/v1/health) && echo "Got Reply from $SERVER_HOST" || echo "Curl failed to connect to $SERVER_HOST" 
    if [ "$var" -eq "OK" ]
    then
        echo "Success"
        break
    fi
done

This does not work and I get the following error -

int-tester_1     | curl: (52) Empty reply from server

I want this to continuously poll the service till the service replies "OK" and then break from the loop.

On changing -eq to = , I get the following error -

int-tester_1     | + var=OK
int-tester_1     | Got Reply from 10.2.223.87
int-tester_1     | + echo 'Got Reply from 10.2.223.87'
int-tester_1     | + '[' = OK ']'
int-tester_1     | ./run_itests.sh: line 33: [: =: unary operator expected

Upvotes: 0

Views: 1628

Answers (1)

Chakra
Chakra

Reputation: 68

Issue could be with following command Is SERVER_HOST getting populated

curl http://${SERVER_HOST}:8060/vmc/vdisizer/api/v1/health

also can you have

(var=$(curl http://${SERVER_HOST}:8060/vmc/vdisizer/api/v1/health)) && echo "Got Reply from $SERVER_HOST" || echo "Curl failed to connect to $SERVER_HOST" 

does curl http://10.2.223.87:8060/vmc/vdisizer/api/v1/health get output ?

something similar to Curl Error 52 Empty reply from server

Upvotes: 1

Related Questions