0
I want to run a script to retrieve results from an api for each day over the last 6 months. The api endpoint uses the date as
/url/yyyy/mm/dd
How can i generate the dates using bash to acheive this?
0
I want to run a script to retrieve results from an api for each day over the last 6 months. The api endpoint uses the date as
/url/yyyy/mm/dd
How can i generate the dates using bash to acheive this?
2
The following script will probably do you - although you might want to calculate 6 months ago (in seconds more exactly - I simply used 31 days * 6).
#! /bin/bash
URL="/url/"
# Key times in seconds
sixmonths=$(( 60 * 60 * 24 * 31 * 6 ))
oneday=$(( 60 * 60 * 24 ))
CURRENTSECS=`/bin/date +%s`
STARTDATEINSECS=$(( $CURRENTSECS - $sixmonths ))
i=$STARTDATEINSECS
while [ $i -le $CURRENTSECS ]
do
echo $URL`/bin/date -d @$i +"%Y/%m/%d"`
i=$(( $i + $oneday ))
done