#!/bin/sh
#
#	This script calls dumpxfer to process the wuftp xferlog and
#	emails the output to people who need to know.  
#	It also moves the current xferlog to a LOGS subdirectory and
#	renames it with the date.  This causes it to truncate the log
#	every time it's run, so it should not be executable by the
#	casual user.  I put it in root's crontab to run every night.
#
# Who to send normal reports to 
good_email="admin,ssizer,peterson"

# Who to send special reports to about bad transfers 
bad_email="admin"

# Where's your xferlog
xferlog="/usr/local/etc/wu-ftpd/xferlog"

# Where do you want to keep archived log files.
# I name them using YYMMDD format because then a directory listing
# is automatically sorted by date.  
newfile="/usr/local/etc/wu-ftpd/LOGS/`date +%y%m%d`"
outfilename="/tmp/dumpxfer.log.$$"
headers="/tmp/dumpxfer.hdr.$$"

# Open log, deleting old entries
#  The reason I do this as a cp then an rm instead of an mv is that
#  the xferlog and the LOGS directory are on different filesystems
#  on my machine, so mv fails.  If they're on the same filesystem,
#  you can combine the two. 
#
cat $xferlog >> $newfile
rm $xferlog
touch $xferlog	# create empty log

/usr/local/bin/dumpxfer -aS -f $newfile > $outfilename
echo "To: $good_email" > $headers
echo "X-Mailbox: xferstats" >> $headers
if [ -s $outfilename ] ; then
	cat $headers $outfilename | /usr/lib/sendmail $good_email 
	fi
rm $outfilename
rm $headers

/usr/local/bin/dumpxfer -bS -f $newfile > $outfilename
echo "To: $good_email" > $headers
echo "X-Mailbox: xferstats" >> $headers
if [ -s $outfilename ] ; then
	cat $headers $outfilename | /usr/lib/sendmail $bad_email 
	fi
rm $outfilename
rm $headers

