]> git.pld-linux.org Git - packages/calamaris.git/blob - calamaris-croniface
- Corrected stupid bug with setting file permissions.
[packages/calamaris.git] / calamaris-croniface
1 #!/bin/sh
2 #
3 # $Id$
4 #
5 # This file is to be called by crond in order to create statistical reports
6 # on usage of caching proxy. It is a wrapper for Calamaris - reads
7 # configuration and calls Calamaris with appropriate arguments.
8 #
9 # One argument should be passed. It can be 'daily' or 'weekly' in order to
10 # select what actions to take.
11 #
12 # Author:       Micha³ Kochanowicz <mkochano@pld.org.pl>
13
14 # Wrapper for Calamaris. Reads configuration and calls Calamaris with
15 # appropriate arguments.
16
17 # Default configuration.
18 SAVE_FORMAT="HTML"
19 SAVE_OWNER="nobody.nobody"
20 SAVE_PERM="u=rw,g=r,o=r"
21 SEND_FORMAT="plain"
22 SEND_TO="root"
23 DAILY_ACTION="send"
24 DAILY_FILES=
25 # If you have an idea of better default setting for this variable you are
26 # welcome to change it, but please don't assume that caching proxy is also
27 # a http server...
28 DAILY_SAVE_AS="/dev/null"
29 WEEKLY_ACTION="send"
30 WEEKLY_FILES=
31 # See comment above.
32 WEEKLY_SAVE_AS="/dev/null"
33 HTML_LOGO="<H1>Caching Proxy Statistics</H1>"
34 CALAMARIS_ARGS="-a"
35
36 # Read configuration.
37 [ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris
38
39 # Parameter passed to Calamaris.
40 ARG_HTML="$CALAMARIS_ARGS -w -l $LOGO"
41 ARG_MAIL="$CALAMARIS_ARGS -a -m Calamaris report"
42 MAIL_SUBJ="Calamaris Report"
43
44 # Calls Calamaris. Requires following arguments:
45 # $1 - Input file (globs are OK).
46 # $2 - Arguments list.
47 call_calamaris() {
48         (
49         for FILE in $1; do
50                 if [[ $FILE = *.gz ]]; then
51                         zcat $FILE
52                 else
53                         cat $FILE
54                 fi
55         done
56         ) | calamaris $2
57 }
58
59 # Processes arguments and prepares arguments for Calamaris. Requires following
60 # arguments:
61 # $1 - Input file (globs are OK).
62 # $2 - Action: "save", "send" or both.
63 # $3 - Save filename.
64 make_stats() {
65         # Generate statistics and save them.
66         if [[ $2 = *save* ]]; then
67                 if [ "$SAVE_FORMAT" = "HTML" ]; then
68                         ARG="$ARG_HTML"
69                 else
70                         ARG="$ARG_PLAIN"
71                 fi
72                 call_calamaris "$1" "$ARG" > $3
73                 chown $SAVE_OWNER $3
74                 chmod $SAVE_PERM $3
75         fi
76
77         # Generate statistics and send them.
78         if [[ $2 = *send* ]]; then
79                 if [ "$SEND_FORMAT" = "HTML" ]; then
80                         ARG="$ARG_HTML"
81                 else
82                         ARG="$ARG_PLAIN"
83                 fi
84                 # If statistics have to be mailed in same format as they were
85                 # saved we don't need to call Calamaris again.
86                 if [[ $2 = *save* && $SAVE_FORMAT = $SEND_FORMAT ]]; then
87                         (
88                         cat $3
89                         ) | mail -s "$MAIL_SUBJ" $SEND_TO
90                 else
91                         call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
92                 fi
93         fi
94 }
95
96
97 if [ "$1" = "daily" ]; then
98         make_stats "$DAILY_FILES" "$DAILY_ACTION" $DAILY_SAVE_AS
99 elif [ "$1" = "weekly" ]; then
100         make_stats "$WEEKLY_FILES" "$WEEKLY_ACTION" $WEEKLY_SAVE_AS
101 else
102         echo 'Make up your mind!' >&2
103 fi
104
This page took 0.089199 seconds and 3 git commands to generate.