1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#!/bin/bash
#
# Debian cron script to generate daily SRG reports. Based on the example
# shipped with the SRG package.
#
# You can configure this cronjob by modifying /etc/default/srg
#
# Author: Matt Brown <matt@mattb.net.nz>
# Version: $Id: srg.cron.daily 313 2008-01-20 00:54:28Z matt $
# Path to SRG binary
SRG=/usr/bin/srg
# Utility to use for sending mail
MAIL_UTIL=/usr/bin/mail
# Log Files - Space separated list of logfiles to process
# eg. LOGS="access1.log access2.log access3.log"
LOGS="/var/log/squid/access.log"
# Get the date range
YESTERDAY=$(date --date "1 day ago" +%Y-%m-%d)
# Check that the SRG binary exists and is executable
test -x $SRG || exit 0
# Read configuration
. /etc/default/srg
if [ -z "$CONFIGFILE" ]; then
# Something is wrong with the configuration.
exit 1
fi
# Check that at least one of the specified logfiles exists
found=0
for log in $LOGS; do
if [ -e $log ]; then
found=1
fi
done
if [ "$found" -eq "0" ]; then
exit 0
fi
# Generate the srg reports
if [ -z $MAILUSER ]; then
$SRG -C $CONFIGFILE -m $DAILY_REPORT_RETAIN_DAYS \
-f $YESTERDAY -t $YESTERDAY -o $REPORTBASE/daily $LOGS
else
$SRG -M -C $CONFIGFILE -m $DAILY_REPORT_RETAIN_DAYS \
-f $YESTERDAY -t $YESTERDAY -o $REPORTBASE/daily \
$LOGS | $MAIL_UTIL -s 'Squid Traffic Report' $MAILUSER
fi
|