#!/bin/sh # 508.sarg-reports if [ -r /etc/defaults/periodic.conf ]; then . /etc/defaults/periodic.conf source_periodic_confs fi : ${sarg_reports_enable="YES"} : ${sarg_reports_current_enable="YES"} : ${sarg_reports_daily_enable="YES"} : ${sarg_reports_monthly_enable="YES"} : ${sarg_reports_dir="/usr/local/www/sarg"} : ${sarg_cmd=/usr/local/bin/sarg} : ${sarg_reports_conf="/usr/local/etc/sarg/sarg-reports.conf"} : ${squid_log_store_dir=/data/log/squid} # Dates variables yesterday=$(date -v -1d +%d/%m/%Y) month_first_date=$(date -v1d +%d/%m/%Y) prev_month_first_date=$(date -v1d -v-1m +%d/%m/%Y) prev_month_last_date=$(date -v1d -v-1d +%d/%m/%Y) datelog=$(date -v-1d +%Y-%m) case "$sarg_reports_enable" in [Yy][Ee][Ss]) # Check squid access.log if [ -f "$squid_log_store_dir/access-$datelog.log" ]; then # Creating sarg config current if not exist if [ ! -f "$sarg_reports_conf" ]; then echo "charset UTF-8" > $sarg_reports_conf echo "graphs no" >> $sarg_reports_conf echo "resolve_ip yes" >> $sarg_reports_conf echo "date_format e" >> $sarg_reports_conf echo "overwrite_report yes" >> $sarg_reports_conf echo "show_successful_message no" >> $sarg_reports_conf echo "show_read_statistics no" >> $sarg_reports_conf echo "show_sarg_logo no" >> $sarg_reports_conf echo "displayed_values abbreviation" >> $sarg_reports_conf fi # Check if sarg report current enable case "$sarg_reports_current_enable" in [Yy][Ee][Ss]) # Creating sarg report current rm -rf $sarg_reports_dir/sarg-current/* $sarg_cmd -f $sarg_reports_conf -l $squid_log_store_dir/access-$datelog.log -o "$sarg_reports_dir/sarg-current" -d $month_first_date-$yesterday > /dev/null 2>&1 ;; *) rc=0;; esac # Check if sarg report daily enable case "$sarg_reports_daily_enable" in [Yy][Ee][Ss]) # Creating sarg report daily $sarg_cmd -f $sarg_reports_conf -l $squid_log_store_dir/access-$datelog.log -o "$sarg_reports_dir/sarg-daily" -d $yesterday-$yesterday > /dev/null 2>&1 ;; *) rc=0;; esac # Check if sarg report monthly enable case "$sarg_reports_monthly_enable" in [Yy][Ee][Ss]) # Creating sarg report monthly if [ `date +%d` -eq 1 ]; then $sarg_cmd -f $sarg_reports_conf -l $squid_log_store_dir/access-$datelog.log -o "$sarg_reports_dir/sarg-monthly" -d $prev_month_first_date-$prev_month_last_date > /dev/null 2>&1 fi ;; *) rc=0;; esac else echo "Error: squid acccess.log file not found!" fi ;; *) rc=0;; esac exit $rc