This script should alert me in case of an error response.
Issue: Even when it executes successfully I am getting the email.
Bash script
#!/bin/bash
DATA=$(wget --timeout 5 -O - -q -t 1 http://this.url/?parm=1\&par=2)
IFS=\" read __ KEY __ MESSAGE __ <<< "$DATA"
if [[ $KEY == Success ]]; then
echo something
else
send email on failure
fi
Response on
Failure: {"ErrorCode":"11","ErrorMessage":"random message as per error code"}
Sucess: {"ErrorCode":"000","ErrorMessage":"Success"}
This worked finally -
#!/bin/bash
DATA=$(wget --timeout 5 -O - -q -t 1 http://this.url/?parm=1\&par=2)
MESSAGE=$(jq '.ErrorMessage' <<< "$DATA")
if [[ "$MESSAGE" == '"Success"' ]] ; then
echo something
else
send email
fi