Sometimes I wonder how people who don’t have UNIX™ utilities at their disposal get along. Scott wrote a script to parse a log file and generate a report. I ran it manually for a while because I needed to run it against a specific set of dates (the last 7 days). This was a problem screaming for automation and UNIX™ to the rescue!
The first step was getting the date for the last 7 days in the right format (2006-06-25), which GNU date was quite good at.
date -d "7 days ago" +%Y-%m-%d
So, I created a file to pass to date that had each date string that I needed (“6 days ago”, “5 days ago”, etc…). So now I was down to just date -f datefile +%Y-%m-%d. Now I needed to loop through that date in my bash script.
DATES=`date -f datefile +%Y-%m-%d`
for mydate in $DATES
do
./hack.sh --date=$mydate >> report.xls
done
Then I just added a dash of mutt -a report.xsl and the report gets sent to the right person every week, right on schedule.