Wrote a Bash script to create two files, each with a list of dates, to be used later. The script requires three parameters: a data subject, a minimum date, and a maximum date. Here's my script:
#!/bin/sh
dataSubj=$1
minDate=$2
maxDate=$3
echo -e "my variables:\nsubject:\t$dataSubj\nstart:\t$minDate\nend:\t$maxDate"
//Wrote the above line for debugging
configDir=/opt/site1/ETL/MFGEDW/config/MERS2
dateCount=1
addTime=00:00:00
fromDates=$dataSubj_fromDates.txt
toDates=$dataSubj_toDates.txt
cd $configDir
echo "Creating fromDates file and adding $minDate"
echo -e "$minDate $addTime" > ./$fromDates
echo "Creating toDates file"
>./$toDates
while [[ $minDate < $maxDate ]]
do
minDate=$(date -d "$minDate 7 days" +%Y-%m-%d)
((dateCount++))
if [[ $minDate < $maxDate ]]; then
echo "Adding $minDate to fromDates file"
echo -e "$minDate $addTime," >> ./$fromDates
fi
echo "Adding $minDate to toDates file"
echo -e "$minDate $addTime," >> ./$toDates
echo "$dateCount dates total"
done
exit $dateCount
My issue is that instead of having two files with the desired dates, I have one hidden file with all the dates that should have been written in the two files. I'm fairly new to scripting, but modeled this after other scripts that I've used and know work. Is there something I'm missing or added unnecessarily? Thanks in advance.