I am trying to download the yesterday logs through an external API, For API I need to provide a date range from & to as input parameters.
From API I can download 1 hour log max for each call.
So if I want to download yesterday complete log. I need to call the API for 24 times with yesterday date(every hour time).
Note API will support only GMT time only. So need to provide GMT time.
Eg :- https://abcd.com/logs?start=FROM_DATE&end=TO_DATE
- First time loop it should go like below,
- https://abcd.com/logs?start=29-04-2018T00:00:00Z&end=29-04-2018T00:59:59Z
- Second time loop it should go like below
- https://abcd.com/logs?start=29-04-2018T01:00:00Z&end=29-04-2018T01:59:59Z
- Last time loop like below,
- https://abcd.com/logs?start=29-04-2018T23:00:00Z&end=29-04-2018T23:59:59Z
This script i will add in cron schedule, so everyday once it will get triggered and download yesterday 24 hour log complete.
Key points are
- Yesterday date always
- Format GMT
- 24 times loop
The below mentioned answers are throwing error. I started with this script, it is considering the current time and doing the loop. Instead of that loop needs to start with 00:00:00 GMT time.
#!/bin/bash
FROM_DATE=$(date -u -d "1 day ago" +%Y-%m-%d"T"%H":00:00""Z")
for i in {0..3}
do
echo "FROM_DATE : $FROM_DATE"
TO_DATE=$(date -u +%Y-%m-%d"T"%H":59:59""Z" -d "1 day ago""$date + $i hour")
echo "TO_DATE : $TO_DATE"
FROM_DATE=$(date -u +%Y-%m-%d"T"%H":00:00""Z" -d "1 day ago""$date + $i hour""$date + 1 hour")
done