Monthly Archiving Script... help with "date" & "cron"
My f/w emails logs to me daily. Those logs are trapped, parsed, and spit out into an HTML page on our monitoring page. This happens daily at 8:00am. For liability reasons, i have to keep all my firewall logs. I've written a script that creates a new dir in the format of Dec02 and copies all the logs from that month into the new dir, thus archiving them monthly. Only one prob... the script is in cron on the 1st of the month... so instead of making a Dec02 dir and copying the Dec files over... it created a Jan03 dir and copied nothing over.
I see two alternatives... A) I make cron run it the last day of the month... but this is problematic as that can vary from the 28 to the 31st. Or B) I make it 'shift' a month... so that when the output of `date` says Jan, it shifts back to Dec.
Any gurus out there have any thoughts on this? Can a "-" be sent to date in some fashion to shift back a month? How do I tell cron to run on the last day of the month when I that varies each month? How would I do this differently?
FYI... this cannot be done in perl. For reasons I won't explain, this must be done in standard shell tools such as date, awk. sed, etc.
My script is below:
>>> begin script <<<
DIR=/home/www/status/bb/firewall/archive
export DIR
# First we set up our new directory and set perms on it
/bin/mkdir $DIR/`date +%b%y`
/bin/chown fwemail:apache $DIR/`date +%b%y`
/bin/chmod 755 $DIR/`date +%b%y`
# Now we move the relevant files to the new directory
/bin/mv $DIR/firewall_log.`date +%m`??`date +%y`.html $DIR/`date +%b%y`
>>> end script <<<
|