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.
9 # One argument should be passed. It can be 'daily' or 'weekly' in order to
10 # select what actions to take.
12 # Author: Micha³ Kochanowicz <mkochano@pld.org.pl>
14 # Wrapper for Calamaris. Reads configuration and calls Calamaris with
15 # appropriate arguments.
17 # Default configuration.
19 SAVE_OWNER="nobody.nobody"
20 SAVE_PERM="u=rw,g=r,o=r"
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
28 DAILY_SAVE_AS="/dev/null"
32 WEEKLY_SAVE_AS="/dev/null"
33 HTML_LOGO="<H1>Caching Proxy Statistics</H1>"
37 [ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris
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"
44 # Calls Calamaris. Requires following arguments:
45 # $1 - Input file (globs are OK).
46 # $2 - Arguments list.
50 if [[ $FILE = *.gz ]]; then
59 # Processes arguments and prepares arguments for Calamaris. Requires following
61 # $1 - Input file (globs are OK).
62 # $2 - Action: "save", "send" or both.
65 # Generate statistics and save them.
66 if [[ $2 = *save* ]]; then
67 if [ "$SAVE_FORMAT" = "HTML" ]; then
72 call_calamaris "$1" "$ARG" > $3
77 # Generate statistics and send them.
78 if [[ $2 = *send* ]]; then
79 if [ "$SEND_FORMAT" = "HTML" ]; then
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
89 ) | mail -s "$MAIL_SUBJ" $SEND_TO
91 call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
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
102 echo 'Make up your mind!' >&2