File: calamaris-cron-script

package info (click to toggle)
calamaris 2.8-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 152 kB
  • ctags: 16
  • sloc: perl: 1,555; sh: 47; makefile: 39
file content (82 lines) | stat: -rw-r--r-- 3,454 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /bin/sh

# calamaris: daily cron script.
# This script should be run before the one for squid. According to the
# man page of run-parts this is okay: squid comes after calamaris in the
# alphabet.

# Date: 1998-10-07

CONFFILE=/etc/calamaris.conf
CALAMARIS=/usr/bin/calamaris
CALAMARISOPTIONS=-a
ME=/etc/cron.daily/calamaris
WEEKFILES=daily.1:daily.2:daily.3:daily.4:daily.5:daily.6:daily.0

SQUIDLOGDIR=/var/log/squid
cd $SQUIDLOGDIR || exit 1
LOGDIR=/var/log/calamaris
cd $LOGDIR || exit 1

# today
DAYOFWEEK=`date +"%w"`

# read configuration file: /etc/calamaris.conf
# is there a more elegant way to do this?
DAYMAIL=`awk -F: '(!/�#/) && ($1 == "daily") { print $2; }' $CONFFILE`
DAYWEB=`awk -F: '(!/�#/) && ($1 == "daily") { print $3; }' $CONFFILE`
DAYDO=`awk -F: '(!/�#/) && ($1 == "daily") { print $4; }' $CONFFILE`
DAYTITLE=`awk -F: '(!/�#/) && ($1 == "daily") { print $5; }' $CONFFILE`

WEEKMAIL=`awk -F: '(!/�#/) && ($1 == "weekly") { print $2; }' $CONFFILE`
WEEKWEB=`awk -F: '(!/�#/) && ($1 == "weekly") { print $3; }' $CONFFILE`
WEEKDO=`awk -F: '(!/�#/) && ($1 == "weekly") { print $4; }' $CONFFILE`
WEEKTITLE=`awk -F: '(!/�#/) && ($1 == "weekly") { print $5; }' $CONFFILE`

# perhaps sometimes I will do this, 
# but as weekends and ends of months don't meet always...

# MONTHMAIL=`awk -F: '(!/�#/) && ($1 == "monthly") { print $2; }' $CONFFILE`
# MONTHWEB=`awk -F: '(!/�#/) && ($1 == "monthly") { print $3; }' $CONFFILE`
# MONTHDO=`awk -F: '(!/�#/) && ($1 == "monthly") { print $4; }' $CONFFILE`
# MONTHTITLE=`awk -F: '(!/�#/) && ($1 == "monthly") { print $5; }' $CONFFILE`

# if we need monthly or weekly reports save a summary
if [ $WEEKDO != "nothing" ]; then
    CALAMARISOPTIONSOLD="$CALAMARISOPTIONS"
    CALAMARISOPTIONS="$CALAMARISOPTIONS -o daily.$DAYOFWEEK"
fi

# do the daily report
case $DAYDO in
    nothing) if [ $WEEKDO != "nothing" ]; then
	cat $SQUIDLOGDIR/access.log | nice -39 $CALAMARIS $CALAMARISOPTIONS > /dev/null
    fi;;
    mail) cat $SQUIDLOGDIR/access.log | nice -39 $CALAMARIS $CALAMARISOPTIONS -mH "$DAYTITLE" | mail $DAYMAIL;;
    web) cat $SQUIDLOGDIR/access.log | nice -39 $CALAMARIS $CALAMARISOPTIONS -wH "$DAYTITLE" > $DAYWEB;;
    both) cat $SQUIDLOGDIR/access.log | nice -39 $CALAMARIS $CALAMARISOPTIONS -wH "$DAYTITLE" > $DAYWEB; cat $SQUIDLOGDIR/access.log | nice -39 $CALAMARIS $CALAMARISOPTIONS -mH "$DAYTITLE" | mail $DAYMAIL;;
    *) echo "the 'todo' for the daily Squid report in $CONFFILE"; echo "is '$DAYDO' instead of one out of (nothing, mail, web, both)."; exit 1;;
esac

# do the weekly report on Sunday <=> $DAYOFWEEK==0
if [ $CALAMARISOPTIONSOLD ]; then
    CALAMARISOPTIONS="$CALAMARISOPTIONSOLD"
fi

if [ $DAYOFWEEK = "0" ]; then
    case $WEEKDO in
	nothing) ;;
	mail) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zmH "$WEEKTITLE" | mail $WEEKMAIL;;
	web) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zwH "$WEEKTITLE" > $WEEKWEB;;
	both) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zwH "$WEEKTITLE" > $WEEKWEB; nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zmH "$WEEKTITLE" | mail $WEEKMAIL;;
	*) echo "the 'todo' for the weekly Squid report in $CONFFILE"; echo "is '$WEEKDO' instead of one out of (nothing, mail, web, both)."; exit 1;;
    esac

#    if [ $MONTHDP != "nothing" ]; then
#	nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -z -o weekly.$WEEKWHAT > /dev/null
#    fi
fi

# do the monthly report and rotate the monthly logs

exit 0