agarwal_achhnera
agarwal_achhnera

Reputation: 2456

how to know connection refused threw curl

In shell script I have to call some service as url by curl command in shell script. In this if the service is not running then curl says connection refused, how can I fetch this exception and call the service running on another machine.

Upvotes: 4

Views: 5546

Answers (2)

Amey Jadiye
Amey Jadiye

Reputation: 3154

You can check the process exit code by curl. FYI http://curl.haxx.se/libcurl/c/libcurl-errors.html

curl  "http://www.my.damn.unreachable.server.com:9090"
if [ "$?" = "7" ]; then 
    echo 'connection refused or cant connect to server/proxy';
fi

Upvotes: 2

anubhava
anubhava

Reputation: 785128

You can check for exit status of curl. For example:

curl -I -A "Chrome" -L "http://localhost:8080"
curl: (7) Failed connect to localhost:8080; Connection refused
[[ $? -eq 7 ]] && curl -I -A "Chrome" -L "http://localhost:9090"

Upvotes: 3

Related Questions