"Fossies" - the Fresh Open Source Software Archive

Member "srg-1.3.6/examples/srg.weekly" (5 Aug 2009, 1884 Bytes) of package /linux/privat/old/srg-1.3.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 #
    3 # Sample script to generate a weekly 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 # A crontab line such as the one below should be used to trigger this script
    9 # 1 0 * * 7       proxy   /usr/local/sbin/srg.weekly
   10 #
   11 # Keeps 2 months (8 weeks) (57 days) worth of weekly reports in the output
   12 # directory.
   13 #
   14 # Author:       Matt Brown <matt@mattb.net.nz>
   15 # Version:      $Id: srg.weekly 243 2008-01-19 18:27:24Z matt $
   16 
   17 # Path to SRG binary
   18 SRG=/usr/bin/srg
   19 
   20 # Utility to use for sending mail
   21 MAIL_UTIL=/usr/bin/mail
   22 
   23 # Top level directory for output reports
   24 REPORTBASE=/var/www/srg_reports
   25 
   26 # Configuration file location
   27 CONFIGFILE=/etc/srg/srg.conf
   28 
   29 # If you would like a summary report emailed to you each night, specify 
   30 # your email address here
   31 # eg. MAILUSER="srg-daily@yourdomain.com"
   32 MAILUSER=""
   33 
   34 # Log Files - Space separated list of logfiles to process
   35 # eg. LOGS="access1.log access2.log access3.log"
   36 LOGS="/var/log/squid/access.log"
   37 
   38 # Working file
   39 TEMPFILE=/tmp/srg.weekly
   40 
   41 # Important Dates
   42 lastmon=$(date --date "1 week ago" +%Y%m)
   43 lastweek=$(date --date "1 week ago" +%m)
   44 yesterday=$(date --date "1 day ago" +%m)
   45 WEEKAGO=$(date --date "1 week ago" +%Y-%m-%d)
   46 YESTERDAY=$(date --date "1 day ago" +%Y-%m-%d)
   47 
   48 # Check that the SRG binary exists and is executable
   49 test -x $SRG || exit 0
   50 
   51 # Make the logfile containing the last weeks data
   52 rm -f $TEMPFILE
   53 for log in $LOGS; do
   54     cat $log >> $TEMPFILE
   55 done
   56 if [ "$yesterday" != "$lastweek" ]; then
   57     for log in $LOGS; do
   58         cat $log-$lastmon >> $TEMPFILE
   59     done
   60 fi
   61     
   62 # Generate the srg reports
   63 $SRG -C $CONFIGFILE -o $REPORTBASE/weekly -m 57 -f $WEEKAGO -t $YESTERDAY:23:59:59 $TEMPFILE &>/dev/null
   64 
   65 # Clean Up
   66 rm -f $TEMPFILE