#!/bin/bash # Greg MacLellan 12/16/2005 # Script for reporting how much mail domains are sending out # http://gregmaclellan.com/php/ # Release notes: http://gregmaclellan.com/blog/sendmail-wrapper/ # Put this script in cron as, eg: # 0 0 * * * /usr/local/sbin/mailreporting.sh delete # for daily reports, or # 0 0 * * 0 /usr/local/sbin/mailreporting.sh delete # for weekly reports. # You can also run it directly (without specifying delete) to get a count of the mail per-domain # path to the mail directory MAILPATH=/var/mail_log # file to use as "compare" file # When running in delete mode, the script will delete any # mail log files older than this file, then set the date # on this file to the current date. Default is to use $0 # (this file) TESTFILE=$0 # header to check for (grep) HEADER="X-Generating-Domain" if [ "$1" == "delete" ]; then find $MAILPATH -not -cnewer $TESTFILE | xargs rm touch $TESTFILE echo "Mail sent by doamins between "`date -r $TESTFILE +%H:%M:%S\ %M\/%d\/%Y`" and "`date +%H:%M:%S\ %M\/%d\/%Y` fi grep "$HEADER" $MAILPATH/* | cut -f 2 -d\ | sort | uniq -c -d