#!/bin/sh
#
# Generates a regular report using monthstats, then mails it off to the designated 
# recipients
#

if ! [ -f /etc/trafstats/mail.conf ]
then
	echo "Not generating automatic usage statistics -- no recipient adresses"
	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

MONTHSTATS=/usr/bin/monthstats
MONTH=`date -d "last month" +%B`

if [ -n "$FSUBJECT" ]
then
	FSUBJECT="Final usage statistics for $MONTH"
fi

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