Problem: For parameters of a minimum and maximum date (ex: script.sh 20190801, 20201005) execute a function on each month within that date range. (ex: 20190801-20190831, 20190901-20190931 . . .)
Backstory: I have a function that generates a CSV based on data from a date range, however for large date ranges this takes too long to run. That in mind, I'm attempting to have this run per-month simultaneously and stitch the CSVs back together afterwards. I would attempt something like this in Python or Javascript and use a datetime library, but certain company limitations are requiring me to exclusively use bash/shell.
Below is my current idea, but it fails in most cases
I get my expected results from passing, for example: 20190101 20201231 to the below code, but I'm unsure how to modify this to support something like 20190105 20200820
DateMin=$1
DateMax=$2
if [ $DateMin -ge $DateMax ]; then
echo "ERROR: Minimum Date Cannot be above Maximum Date"
exit
fi
let DateDelta=DateMax-DateMin
for YearDelta in `seq $DateDelta -10000 0`
do
let TempDelta=$YearDelta-1130
for MonthDelta in `seq $YearDelta -100 $TempDelta`
do
let TempMin=$DateMax-$MonthDelta
let TempMax=$DateMax-$MonthDelta+30
call_to_function $TempMin $TempMax
done
done
I created a repl.it here so it's easier to see: https://repl.it/repls/CanineAdmirableSeahorse#main.sh If you run "bash main.sh 20190101 20201231" that's the expected output.