I am trying to use curl with a URL containing two dates. How can I use the values of two variables containing date/time stamps instead of hard coded dates in the URL? I want to use a range from 50 minutes ago to the current time.
Here is my code with hard coded date/time values:
#!/bin/bash
currentTime=$(date +"%R")
currentdate=$(date +'%m/%d/%Y')
oldtime=$(date +%R -d "50 min ago")
echo "Current time : $currentTime"
echo "Current Date : $currentdate"
echo "Old time : $oldtime"
Response=$(curl -X GET -H "Authorization: Basic Token=" "http://targetserver.companyname.com:8080/v1/organizations/companyname/environments/environmentname/stats/apis?select=sum(is_error)&timeRange=01/24/2017%2002:00~01/25/2017%2006:00")
I tried replacing the hard coded dates as follows, but it didn't work:
Response=$(curl -X GET -H "Authorization: Basic Token=" "http://targetserver.company.com:8080/v1/organizations/company/environments/environmentname/stats/apis?select=sum(is_error)&timeRange="$currentdate" "$currentTime"~"$currentdate" "$oldtime"")
I made a working example, here: