#!/bin/sh

# MAILSTAT - Script to Email procmail mailstats to postmaster
# 17 August 2002
#
# Script will email the users of a VmailMGR virtual domain
# the following information:

#

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin

# Set the following 4 variables:
# 1. Your domain name
DOMAIN=domain.net

# 2. user file contains one user per line
LIST=/home/dom/proc/.users

# 3. path to mailstat
MAILSTATPROG=/usr/local/bin/mailstat

# 4. path to proc logs
PROCLOG=/home/dom/logs

# lets get started
echo "  Mailstat for `date +%Y-%m-%d`" >> /tmp/mailstat.tmp
echo "*************************" >> /tmp/mailstat.tmp
for user in `cat $LIST`; do

$MAILSTATPROG $PROCLOG/procmail-$user.log >> /tmp/mailstat-$user.tmp

# Let send mail if there is data
SIZE=`cat /tmp/mailstat-$user.tmp | wc -l`
NUM=1

if [ $NUM -lt $SIZE ];
then
    echo >> /tmp/mailstat.tmp
    echo "***** $user *****" >> /tmp/mailstat.tmp
    more /tmp/mailstat-$user.tmp >> /tmp/mailstat.tmp
    echo >> /tmp/mailstat.tmp
fi

rm $PROCLOG/procmail-$user.log
rm /tmp/mailstat-$user.tmp

done

SIZE2=`cat /tmp/mailstat.tmp | wc -l`
NUM2=4

echo >> /tmp/mailstat.tmp
echo "*** End of File ***" >> /tmp/mailstat.tmp

if [ $NUM2 -lt $SIZE2 ];
then
    more /tmp/mailstat.tmp | mail -s "Mailstat for `date +%Y-%m-%d`" postmaster@$DOMAIN
fi

rm /tmp/mailstat.tmp

exit 0


