1 #!/bin/bash 2 # 3 # Sample script to generate a daily SRG report. This script assumes that you 4 # rotate your squid logfiles on a monthly basis using the srg.monthly 5 # script provided along with this one. If you have a different scheme you 6 # may need to modify this script. 7 # 8 # This script is designed to be run close after midnight to generate a report 9 # for the previous day. 10 # Use a crontab line such as the one below to trigger this script. 11 # 1 0 * * * proxy /usr/local/sbin/srg.daily 12 # 13 # Keeps 1 months (31 days) worth of daily reports in the output directory. 14 # 15 # Author: Matt Brown <matt@mattb.net.nz> 16 # Version: $Id: srg.daily 243 2008-01-19 18:27:24Z matt $ 17 18 # Path to SRG binary 19 SRG=/usr/bin/srg 20 21 # Utility to use for sending mail 22 MAIL_UTIL=/usr/bin/mail 23 24 # Top level directory for output reports 25 REPORTBASE=/var/www/srg_reports 26 27 # Configuration file location 28 CONFIGFILE=/etc/srg/srg.conf 29 30 # If you would like a summary report emailed to you each night, specify 31 # your email address here 32 # eg. MAILUSER="srg-daily@yourdomain.com" 33 MAILUSER="" 34 35 # Log Files - Space separated list of logfiles to process 36 # eg. LOGS="access1.log access2.log access3.log" 37 LOGS="/var/log/squid/access.log" 38 39 # Get the date range 40 YESTERDAY=$(date --date "1 day ago" +%Y-%m-%d) 41 42 # Check that the SRG binary exists and is executable 43 test -x $SRG || exit 0 44 45 # Check that at least one of the specified logfiles exists 46 found=0 47 for log in $LOGS; do 48 if [ -e $log ]; then 49 found=1 50 fi 51 done 52 if [ "$found" -eq "0" ]; then 53 exit 0 54 fi 55 56 # Generate the srg reports 57 if [ -z $MAILUSER ]; then 58 $SRG -C $CONFIGFILE -m 31 -f $YESTERDAY -t $YESTERDAY -o $REPORTBASE/daily $LOGS 59 else 60 $SRG -M -C $CONFIGFILE -m 31 -f $YESTERDAY -t $YESTERDAY -o $REPORTBASE/daily $LOGS | $MAIL_UTIL -s 'Squid Traffic Report' $MAILUSER 61 fi