File: srg.weekly

package info (click to toggle)
srg 1.3.5-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,956 kB
  • ctags: 776
  • sloc: sh: 9,073; cpp: 3,383; ansic: 563; makefile: 74; php: 57; yacc: 35; lex: 30
file content (66 lines) | stat: -rwxr-xr-x 1,884 bytes parent folder | download
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#
# Sample script to generate a weekly SRG report. This script assumes that you
# rotate your squid logfiles on a monthly basis using the srg.monthly
# script provided along with this one. If you have a different scheme you
# may need to modify this script.
#
# A crontab line such as the one below should be used to trigger this script
# 1 0 * * 7       proxy   /usr/local/sbin/srg.weekly
#
# Keeps 2 months (8 weeks) (57 days) worth of weekly reports in the output
# directory.
#
# Author:       Matt Brown <matt@mattb.net.nz>
# Version:      $Id: srg.weekly 246 2008-01-19 23:13:17Z matt $

# Path to SRG binary
SRG=/usr/bin/srg

# Utility to use for sending mail
MAIL_UTIL=/usr/bin/mail

# Top level directory for output reports
REPORTBASE=/var/www/srg_reports

# Configuration file location
CONFIGFILE=/etc/srg/srg.conf

# If you would like a summary report emailed to you each night, specify 
# your email address here
# eg. MAILUSER="srg-daily@yourdomain.com"
MAILUSER=""

# Log Files - Space separated list of logfiles to process
# eg. LOGS="access1.log access2.log access3.log"
LOGS="/var/log/squid/access.log"

# Working file
TEMPFILE=/tmp/srg.weekly

# Important Dates
lastmon=$(date --date "1 week ago" +%Y%m)
lastweek=$(date --date "1 week ago" +%m)
yesterday=$(date --date "1 day ago" +%m)
WEEKAGO=$(date --date "1 week ago" +%Y-%m-%d)
YESTERDAY=$(date --date "1 day ago" +%Y-%m-%d)

# Check that the SRG binary exists and is executable
test -x $SRG || exit 0

# Make the logfile containing the last weeks data
rm -f $TEMPFILE
for log in $LOGS; do
    cat $log >> $TEMPFILE
done
if [ "$yesterday" != "$lastweek" ]; then
    for log in $LOGS; do
        cat $log-$lastmon >> $TEMPFILE
    done
fi
	
# Generate the srg reports
$SRG -C $CONFIGFILE -o $REPORTBASE/weekly -m 57 -f $WEEKAGO -t $YESTERDAY:23:59:59 $TEMPFILE &>/dev/null

# Clean Up
rm -f $TEMPFILE