5
# calamaris: daily cron script.
6
# This script should be run before the one for squid or oops. According to the
7
# man page of run-parts this is okay: squid and oops come after calamaris in
14
CONFFILE=/etc/calamaris/cron.conf
15
CALAMARIS=/usr/bin/calamaris
16
CALAMARIS_CONF_FILE=/etc/calamaris/calamaris.conf
18
if [ ! -x /usr/bin/calamaris ]; then
22
CALAMARISOPTIONS="-a -f auto --config-file ${CALAMARIS_CONF_FILE}"
24
ME=/etc/cron.daily/calamaris
25
WEEKFILES=forweekly.1:forweekly.2:forweekly.3:forweekly.4:forweekly.5:forweekly.6:forweekly.0
28
DAYOFWEEK=`date +"%w"`
29
DAYOFMONTH=`date +"%d" | bc -l`
30
# WEEKOFYEAR=`date +"%W"`
33
# read configuration file: /etc/calamaris/cron.conf
36
'(!/�#/) && ($1 == "daily") {
37
print "DAYMAIL=" $2; print "DAYWEB=" $3;
38
print "DAYDO=" $4; print "DAYTITLE=" $5;
40
DAYWEBPATH=`dirname $DAYWEB`
41
DAYWEBFILE=`basename $DAYWEB`
45
'(!/�#/) && ($1 == "weekly") {
46
print "WEEKMAIL=" $2; print "WEEKWEB=" $3;
47
print "WEEKDO=" $4; print "WEEKTITLE=" $5;
49
WEEKWEBPATH=`dirname $WEEKWEB`
50
WEEKWEBFILE=`basename $WEEKWEB`
54
'(!/�#/) && ($1 == "monthly") {
55
print "MONTHMAIL=" $2; print "MONTHWEB=" $3;
56
print "MONTHDO=" $4; print "MONTHTITLE=" $5;
58
MONTHWEBPATH=`dirname $MONTHWEB`
59
MONTHWEBFILE=`basename $MONTHWEB`
64
'(!/�#/) && ($1 == "cache") {
71
'(!/�#/) && ($1 == "cachefile") {
72
print "CACHEFILE=" $2;
75
# look for cache log files
76
if [ "$CACHE" = "auto" ]; then
77
if [ -r /var/log/squid/$CACHEFILE ]; then
79
CACHELOGDIR=/var/log/squid
81
if [ -r /var/log/oops/$CACHEFILE ]; then
83
CACHELOGDIR=/var/log/oops
85
if [ "$CACHE" = "auto" ]; then
86
echo "/etc/cron.daily/calamaris: no cache log files found, exiting cleanly"
90
CACHELOGDIR=/var/log/$CACHE
91
if [ ! -r $CACHELOGDIR/$CACHEFILE ]; then
92
echo "/etc/cron.daily/calamaris: no cache log files found in $CACHELOGDIR, exiting cleanly"
97
# change to working dir
98
LOGDIR=/var/log/calamaris
101
# if we need monthly or weekly reports save a summary
102
if [ "$WEEKDO" != "nothing" ]; then
103
CALAMARISOPTIONSOLD="$CALAMARISOPTIONS"
104
CALAMARISOPTIONS="$CALAMARISOPTIONS -o forweekly.$DAYOFWEEK"
105
# Ensure that this file exists and is empty; if there are no entries in the
106
# squid access.log, calamaris won't create the summary file, which causes
107
# problems with the weekly and monthly summaries.
108
:> forweekly.$DAYOFWEEK
110
if [ "$MONTHDO" != "nothing" ]; then
111
CALAMARISOPTIONSOLD="$CALAMARISOPTIONS"
112
CALAMARISOPTIONS="$CALAMARISOPTIONS -o formonthly.$DAYOFMONTH"
116
# do the daily report
118
nothing) if [ "$WEEKDO" != "nothing" ]; then
119
cat $CACHELOGDIR/$CACHEFILE | \
120
nice -39 $CALAMARIS $CALAMARISOPTIONS > /dev/null
123
mail) if [ -x /usr/sbin/sendmail ]; then (
125
echo "From: Calamaris <root>"
126
cat $CACHELOGDIR/$CACHEFILE | \
127
nice -39 $CALAMARIS $CALAMARISOPTIONS -F mail -H "$DAYTITLE"
128
) | /usr/sbin/sendmail -t
131
web) cat $CACHELOGDIR/$CACHEFILE | \
132
nice -39 $CALAMARIS $CALAMARISOPTIONS $HTMLOPTIONS -H "$DAYTITLE" \
133
--output-path $DAYWEBPATH --output-file $DAYWEBFILE
135
both) cat $CACHELOGDIR/$CACHEFILE | \
136
nice -39 $CALAMARIS $CALAMARISOPTIONS $HTMLOPTIONS -H "$DAYTITLE" \
137
--output-path $DAYWEBPATH --output-file $DAYWEBFILE
138
if [ -x /usr/sbin/sendmail ]; then (
140
echo "From: Calamaris <root>"
141
cat $CACHELOGDIR/$CACHEFILE | \
142
nice -39 $CALAMARIS $CALAMARISOPTIONS -F mail -H "$DAYTITLE"
143
) | /usr/sbin/sendmail -t
146
*) echo "the 'todo' for the daily Squid report in $CONFFILE"
147
echo -n "is '$DAYDO' instead of one out of "
148
echo "(nothing, mail, web, both)." >&2
153
if [ "$MONTHDO" != "nothing" -a "$WEEKDO" != "nothing" ]; then
154
cp forweekly.$DAYOFWEEK formonthly.$DAYOFMONTH
157
# do the weekly report on Sunday <=> $DAYOFWEEK==0
158
if [ -n "$CALAMARISOPTIONSOLD" ]; then
159
CALAMARISOPTIONS="$CALAMARISOPTIONSOLD"
162
if [ "$DAYOFWEEK" = "0" ]; then
163
# make sure, all forweekly files exist, ie. touch them
164
touch `echo $WEEKFILES | sed "s/:/ /g"`
168
mail) if [ -x /usr/sbin/sendmail ]; then (
170
echo "From: Calamaris <root>"
171
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
172
-z -F mail -H "$WEEKTITLE"
173
) | /usr/sbin/sendmail -t
176
web) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
177
-z $HTMLOPTIONS -H "$WEEKTITLE" \
178
--output-path $WEEKWEBPATH --output-file $WEEKWEBFILE
180
both) if [ "$DEBUG" = "1" ]; then
182
echo "Doing web stats: nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zwH \"$WEEKTITLE\" into $WEEKWEB"
184
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
185
-z $HTMLOPTIONS -H "$WEEKTITLE" \
186
--output-path $WEEKWEBPATH --output-file $WEEKWEBFILE
187
if [ "$DEBUG" = "1" ]; then
188
echo "Doing mail stats: nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zmH \"$WEEKTITLE\""
190
if [ -x /usr/sbin/sendmail ]; then (
192
echo "From: Calamaris <root>"
193
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
194
-z -F mail -H "$WEEKTITLE"
195
) | /usr/sbin/sendmail -t
197
if [ "$DEBUG" = "1" ]; then echo "Finished weekly stats."; fi
199
*) echo "the 'todo' for the weekly Squid report in $CONFFILE"
200
echo -n "is '$WEEKDO' instead of one out of "
201
echo "(nothing, mail, web, both)." >&2
205
# remove all forweekly files (could disturb next week's statistics if
206
# computer is switched of one day)
207
rm -f `echo $WEEKFILES | sed "s/:/ /g"`
210
# do the monthly report
211
if [ "$DAYOFMONTH" = "1" ]; then
213
MONTHFILES=formonthly.1
214
yesterday=`date +"%d" -d "yesterday"`
215
end=`echo 1+$yesterday | bc -l`
216
while [ "$i" != $end ]; do
217
MONTHFILES=$MONTHFILES:formonthly.$i
218
i=`echo 1+$i | bc -l`
220
# make sure, all formonthly files exist, ie. touch them
221
touch `echo $MONTHFILES | sed "s/:/ /g"`
225
mail) if [ -x /usr/sbin/sendmail ]; then (
226
echo "To: $MONTHMAIL"
227
echo "From: Calamaris <root>"
228
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
229
-z -F mail -H "$MONTHTITLE"
230
) | /usr/sbin/sendmail -t
233
web) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
234
-z $HTMLOPTIONS -H "$MONTHTITLE" \
235
--output-path $MONTHWEBPATH --output-file $MONTHWEBFILE
237
both) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
238
-z $HTMLOPTIONS -H "$MONTHTITLE" \
239
--output-path $MONTHWEBPATH --output-file $MONTHWEBFILE
240
if [ -x /usr/sbin/sendmail ]; then (
241
echo "To: $MONTHMAIL"
242
echo "From: Calamaris <root>"
243
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
244
-z -F mail -H "$MONTHTITLE"
245
) | /usr/sbin/sendmail -t
248
*) echo "the 'todo' for the weekly Squid report in $CONFFILE"
249
echo -n "is '$MONTHDO' instead of one out of "
250
echo "(nothing, mail, web, both)." >&2
254
# remove all formonthly files (could disturb next month's statistics if
255
# computer is switched of one day)