I am working on a project in which I need to make a url call to one of my server from the bash shell script..
http://hostname.domain.com:8080/beat
After hitting the above url, I will be getting the below response which I need to parse it and extract value of state from it
num_retries_allowed: 3 count: 30 count_behind: 100 state: POST_INIT num_rounds: 60 hour_col: 2 day_col: 0
Now I want to extract state variable value using regular expressions. I am able to extract count and count_behind value from it but not sure how to extract state value from it.
#send the request, put response in variable
DATA=$(wget -O - -q -t 1 http://hostname.domain.com:8080/beat)
#grep $DATA for count and count_behind
COUNT=$(echo $DATA | grep -oE 'count: [0-9]+' | awk '{print $2}')
COUNT_BEHIND=$(echo $DATA | grep -oE 'count_behind: [0-9]+' | awk '{print $2}')
# how to extract state variable value here?
STATE= what do I add here?
Also if in $DATA if state variable is not there by any chance, then I want to assign 0 to STATE variable. After that I want to verify the conditionals and exit out of the script depending on that.
If STATE is equal to POST_INIT then exit successfully out of the shell script or STATE is equal to 0, then exit successfully as well.
#verify conditionals
if [[ $STATE -eq "POST_INIT" || $STATE -eq "0" ]]; then exit 0; fi