1
URL=$(curl -i -X GET -H "Authorization: Basic token=" -H "Cache-Control: no-cache" -H "http://company url:8080/v1/organizations/wiley/environments/api-team-ci1/stats/apis?select=sum(is_error)&timeRange=01/24/2017%2002:00~01/25/2017%2006:00") 

URL should return a JSON response which I need to parse and grab some values. Not even getting response from the curl command; getting only "curl: no URL specified!" error. Please help me and direct as I am trying to do it for the first time.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
A. Datta
  • 41
  • 1
  • 2
  • 5

1 Answers1

0

You're passing the URL as an argument to -H, but it's not a header – remove the -H before the URL:

url=$(curl -i -X GET -H "Authorization: Basic token=" -H "Cache-Control: no-cache" \
"http://company url:8080/v1/organizations/wiley/environments/api-team-ci1/stats/apis?select=sum(is_error)&timeRange=01/24/2017%2002:00~01/25/2017%2006:00")
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • Thanks for the help. After I posted the question I was trying different ways and was able to get response successfully. It's JSON response. Could you tell me how do I find a particular error value (which is 6 here) and if it goes above 10 an email will be generated. please see the response below - { "environments" : [ { "dimensions" : [ { "metrics" : [ { "name" : "sum(is_error)", "values" : [ "6.0" ] } ], "name" : "asiag-api" } ], "name" : "api-xyz" } ], "metaData" : { "errors" : [ ], – A. Datta Jan 26 '17 at 00:28
  • You're asking "how to parse JSON" and "how to send email from the command line", which seem unrelated to the question at hand. Have a look at [this question](http://stackoverflow.com/questions/41093119/how-to-parse-json-with-shell-scripting) and [jq](https://github.com/stedolan/jq) for JSON parsing; check [this question](http://stackoverflow.com/questions/20318770/send-mail-from-linux-terminal-in-one-line) for sending mail from the command line. – Benjamin W. Jan 26 '17 at 01:48