#!/bin/sh -e
#
# trafstats maintenance: Clean up and maintain the database integrity; also
# generates a regular report using monthstats, then mails it off to the 
# designated recipients
#

[ -f /etc/trafstats/trafstats.conf ] || exit 0

. /etc/trafstats/trafstats.conf

if ! [ -f /etc/trafstats/mail.conf ]
then
	exit 0
fi

if ! [ -x /usr/bin/monthstats ]
then
        # assume uninstalled but not purged
	exit 0
fi

. /etc/trafstats/mail.conf

if ! [ -n "$RECIPIENTS" ]
then
	exit 0
fi
SUBJECT=`date +"Usage tally for %B up to %b %d"`
MONTHSTATS=/usr/bin/monthstats
MONTH=`date +%B`

$MONTHSTATS $MONTH | mail -s "$SUBJECT" $RECIPIENTS 

