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
How can i generate the dates using bash to acheive this?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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