I guess what you are trying to recover is a HTTP Code stating that the request was successful, in that case you can try this:
HTTP_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $URL)
This will print the HTTP status of the request done, for instance:
HTTP_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://www.google.com)
echo $HTTP_RESPONSE
301
200 and 30X codes indicate a working server. If you don´t get result, then it is time to check CURL exit code:
if [ $? -eq 7 ] then ...
Being 7 the code returned when CURL can not connect to the host:
- Failed to connect to host. curl managed to get an IP address to the machine and it tried to setup a TCP connection to the host but failed. This can be because you have specified the wrong port number, entered the wrong host name, the wrong protocol or perhaps because there is a firewall or another network equipment in between that blocks the traffic from getting through
See all codes:
https://ec.haxx.se/usingcurl-returns.html
UPDATE: As discussed in the comments, the question is not clear on whether the check is to be done in the HTTP Status code or in a JSON payload (which is missing). In case you want to check the payload, this can be used:
URL Serving a dummy JSON:
https://jsonplaceholder.typicode.com/todos/2
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
}
To parse this, this can be used (let´s pretend we want to check the "title"):
$ curl -s https://jsonplaceholder.typicode.com/todos/2 | grep -Po '"title": ".*' | cut -f 4 -d '"'
This matches only the specified pattern and extracts the value.