I am new to shell script and I am trying to log the message with curl and grep command.
following is curl command
curl --cacert ds***ds*DS*ghgjhg** > /data/result.out
Here this curl command run and create result.out file.
And following is the result in log file.
result.out
{
"data": [
{
"numberOfRecords": 15,
"objectType": "abc"
},
{
"numberOfRecords": 10,
"objectType": "pqr"
},
{
"numberOfRecords": 32,
"objectType": "xyz"
}
],
"errors": [
{
"errorMessage": "java.sql.SQLException:",
"objectType": "xxx"
}
]
}
I want check if there are any errors array and have errorMessage then
log "curl command failed.. " + errorMessage.
else
log "curl command succesfully executed"
It tried.
if grep -w "errors" /data/result.out; then
echo "curl command failed." + errorMessage
else
echo "curl command succesfully executed"
exit 1
It checks for errors string but, not sure how to check if there are any child and if yes then fetching errorMessage. Tried to find solution but, couldn't find any proper.