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.conf
15
CALAMARIS=/usr/bin/calamaris
17
if [ ! -x /usr/bin/calamaris ]; then
21
CALAMARISOPTIONS='-a -f auto'
22
ME=/etc/cron.daily/calamaris
23
WEEKFILES=forweekly.1:forweekly.2:forweekly.3:forweekly.4:forweekly.5:forweekly.6:forweekly.0
26
DAYOFWEEK=`date +"%w"`
27
DAYOFMONTH=`date +"%d" | bc -l`
28
# WEEKOFYEAR=`date +"%W"`
31
# read configuration file: /etc/calamaris.conf
34
'(!/�#/) && ($1 == "daily") {
35
print "DAYMAIL=" $2; print "DAYWEB=" $3;
36
print "DAYDO=" $4; print "DAYTITLE=" $5;
41
'(!/�#/) && ($1 == "weekly") {
42
print "WEEKMAIL=" $2; print "WEEKWEB=" $3;
43
print "WEEKDO=" $4; print "WEEKTITLE=" $5;
48
'(!/�#/) && ($1 == "monthly") {
49
print "MONTHMAIL=" $2; print "MONTHWEB=" $3;
50
print "MONTHDO=" $4; print "MONTHTITLE=" $5;
56
'(!/�#/) && ($1 == "cache") {
60
# look for cache log files
61
if [ "$CACHE" = "auto" ]; then
62
if [ -r /var/log/squid/access.log ]; then
64
CACHELOGDIR=/var/log/squid
66
if [ -r /var/log/oops/access.log ]; then
68
CACHELOGDIR=/var/log/oops
70
if [ "$CACHE" = "auto" ]; then
71
echo "/etc/cron.daily/calamaris: no cache log files found, exiting cleanly"
75
CACHELOGDIR=/var/log/$CACHE
76
if [ ! -r $CACHELOGDIR/access.log ]; then
77
echo "/etc/cron.daily/calamaris: no cache log files found in $CACHELOGDIR, exiting cleanly"
82
# change to working dir
83
LOGDIR=/var/log/calamaris
86
# if we need monthly or weekly reports save a summary
87
if [ "$WEEKDO" != "nothing" ]; then
88
CALAMARISOPTIONSOLD="$CALAMARISOPTIONS"
89
CALAMARISOPTIONS="$CALAMARISOPTIONS -o forweekly.$DAYOFWEEK"
91
if [ "$MONTHDO" != "nothing" ]; then
92
CALAMARISOPTIONSOLD="$CALAMARISOPTIONS"
93
CALAMARISOPTIONS="$CALAMARISOPTIONS -o formonthly.$DAYOFMONTH"
99
nothing) if [ "$WEEKDO" != "nothing" ]; then
100
cat $CACHELOGDIR/access.log | \
101
nice -39 $CALAMARIS $CALAMARISOPTIONS > /dev/null
104
mail) if [ -x /usr/sbin/sendmail ]; then (
106
echo "From: Calamaris <root>"
107
cat $CACHELOGDIR/access.log | \
108
nice -39 $CALAMARIS $CALAMARISOPTIONS -F mail -H "$DAYTITLE"
109
) | /usr/sbin/sendmail -t
112
web) cat $CACHELOGDIR/access.log | \
113
nice -39 $CALAMARIS $CALAMARISOPTIONS -F html -H "$DAYTITLE" > $DAYWEB
115
both) cat $CACHELOGDIR/access.log | \
116
nice -39 $CALAMARIS $CALAMARISOPTIONS -F html -H "$DAYTITLE" > $DAYWEB
117
if [ -x /usr/sbin/sendmail ]; then (
119
echo "From: Calamaris <root>"
120
cat $CACHELOGDIR/access.log | \
121
nice -39 $CALAMARIS $CALAMARISOPTIONS -F mail -H "$DAYTITLE"
122
) | /usr/sbin/sendmail -t
125
*) echo "the 'todo' for the daily Squid report in $CONFFILE"
126
echo -n "is '$DAYDO' instead of one out of "
127
echo "(nothing, mail, web, both)." >&2
132
if [ "$MONTHDO" != "nothing" -a "$WEEKDO" != "nothing" ]; then
133
cp forweekly.$DAYOFWEEK formonthly.$DAYOFMONTH
136
# do the weekly report on Sunday <=> $DAYOFWEEK==0
137
if [ -n "$CALAMARISOPTIONSOLD" ]; then
138
CALAMARISOPTIONS="$CALAMARISOPTIONSOLD"
141
if [ "$DAYOFWEEK" = "0" ]; then
142
# make sure, all forweekly files exist, ie. touch them
143
touch `echo $WEEKFILES | sed "s/:/ /g"`
147
mail) if [ -x /usr/sbin/sendmail ]; then (
149
echo "From: Calamaris <root>"
150
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
151
-z -F mail -H "$WEEKTITLE"
152
) | /usr/sbin/sendmail -t
155
web) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
156
-z -F html -H "$WEEKTITLE" > $WEEKWEB
158
both) if [ "$DEBUG" = "1" ]; then
160
echo "Doing web stats: nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zwH \"$WEEKTITLE\" into $WEEKWEB"
162
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
163
-z -F html -H "$WEEKTITLE" > $WEEKWEB
164
if [ "$DEBUG" = "1" ]; then
165
echo "Doing mail stats: nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -zmH \"$WEEKTITLE\""
167
if [ -x /usr/sbin/sendmail ]; then (
169
echo "From: Calamaris <root>"
170
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
171
-z -F mail -H "$WEEKTITLE"
172
) | /usr/sbin/sendmail -t
174
if [ "$DEBUG" = "1" ]; then echo "Finished weekly stats."; fi
176
*) echo "the 'todo' for the weekly Squid report in $CONFFILE"
177
echo -n "is '$WEEKDO' instead of one out of "
178
echo "(nothing, mail, web, both)." >&2
182
# remove all forweekly files (could disturb next week's statistics if
183
# computer is switched of one day)
184
rm -f `echo $WEEKFILES | sed "s/:/ /g"`
187
# do the monthly report
188
if [ "$DAYOFMONTH" = "1" ]; then
190
MONTHFILES=formonthly.1
191
yesterday=`date +"%d" -d "yesterday"`
192
end=`echo 1+$yesterday | bc -l`
193
while [ "$i" != $end ]; do
194
MONTHFILES=$MONTHFILES:formonthly.$i
195
i=`echo 1+$i | bc -l`
197
# make sure, all formonthly files exist, ie. touch them
198
touch `echo $MONTHFILES | sed "s/:/ /g"`
202
mail) if [ -x /usr/sbin/sendmail ]; then (
203
echo "To: $MONTHMAIL"
204
echo "From: Calamaris <root>"
205
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
206
-z -F mail -H "$MONTHTITLE"
207
) | /usr/sbin/sendmail -t
210
web) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
211
-z -F html -H "$MONTHTITLE" > $MONTHWEB
213
both) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
214
-z -F html -H "$MONTHTITLE" > $MONTHWEB
215
if [ -x /usr/sbin/sendmail ]; then (
216
echo "To: $MONTHMAIL"
217
echo "From: Calamaris <root>"
218
nice -39 $CALAMARIS $CALAMARISOPTIONS -i $MONTHFILES \
219
-z -F mail -H "$MONTHTITLE"
220
) | /usr/sbin/sendmail -t
223
*) echo "the 'todo' for the weekly Squid report in $CONFFILE"
224
echo -n "is '$MONTHDO' instead of one out of "
225
echo "(nothing, mail, web, both)." >&2
229
# remove all formonthly files (could disturb next month's statistics if
230
# computer is switched of one day)