aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xeximstats-cron68
1 files changed, 34 insertions, 34 deletions
diff --git a/eximstats-cron b/eximstats-cron
index 8306760..a4f3052 100755
--- a/eximstats-cron
+++ b/eximstats-cron
@@ -8,29 +8,26 @@ set -o nounset
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
set -o pipefail
+### Options
STATDIR="/var/www/eximstats.dnns.no"
-# Daily
+### Functions
-daily="${STATDIR}/"$(date --date '-1 day' "+%Y/%m/%d.html")
-[[ -d "$(dirname ${daily})" ]] || mkdir -p $(dirname "${daily}")
-eximstats -html="${daily}" /var/log/exim4/mainlog-$(date --date '-1 day' "+%Y%m%d")
-
-folder="${STATDIR}/yesterday"
-[[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}"
-cd "${folder}"
-eximstats -charts -html="index.html" /var/log/exim4/mainlog-$(date --date '-1 day' "+%Y%m%d")
-
-
-function stats_for_last_n_days () {
- folder="${STATDIR}/last ${1} days"
+# This function creates the folder if it does not exist, and it empties it if it does exist.
+function cdir () {
+ local folder="${STATDIR}/${1}"
[[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}"
cd "${folder}"
+}
+
+# This tallies up last n days of statistics
+function stats_for_last_n_days () {
+ cdir "last ${1} days"
- files=""
- n=${1};
+ local files=""
+ local n=${1};
while [[ ${n} -gt 0 ]];
do
day="${STATDIR}/"$(date --date "-${n} days" "+%Y/%m/%d.html")
@@ -40,40 +37,43 @@ function stats_for_last_n_days () {
eximstats -charts -merge -html="index.html" ${files}
}
-# weekly
-stats_for_last_n_days 7
+### Let's roll
-# monthly
+# Daily (/YYYY/mm/dd.html)
+daily="${STATDIR}/"$(date --date '-1 day' "+%Y/%m/%d.html")
+[[ -d "$(dirname ${daily})" ]] || mkdir -p $(dirname "${daily}")
+eximstats -html="${daily}" /var/log/exim4/mainlog-$(date --date '-1 day' "+%Y%m%d")
+
+# Yesterday (/yesterday/)
+cdir "yesterday"
+eximstats -charts -html="index.html" /var/log/exim4/mainlog-$(date --date '-1 day' "+%Y%m%d")
+# Weekly (/last 7 days/)
+stats_for_last_n_days 7
+
+# Monthly (/last 30 days/)
stats_for_last_n_days 30
-# update this months total, unless it is the first of the month
+# Update this months total, unless it is the first of the month
if [[ $(date '+%d') != 01 ]]; then
- folder="${STATDIR}/"$(date "+%Y/%m/total")
- [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}"
- cd "${folder}"
+ # This month (/YYYY/mm/total/)
+ cdir "$(date '+%Y/%m/total')"
eximstats -charts -merge -html="index.html" ../*.html
fi
# If it's the first of the month, do monthly total for last month.
# Also, we update the total for the year.
if [[ $(date '+%d') == 01 ]]; then
- # Monthly
- folder="${STATDIR}/"$(date --date '-1 day' "+%Y/%m/total")
- [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}"
- cd "${folder}"
+ # Last month (/YYYY/mm/total/)
+ cdir "$(date --date '-1 day' '+%Y/%m/total')"
eximstats -charts -merge -html="index.html" ../*.html
- # Yearly
- folder="${STATDIR}/"$(date --date '-1 day' "+%Y/total")
- [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}"
- cd "${folder}"
+ # Yearly (/YYYY/total/)
+ cdir "$(date --date '-1 day' '+%Y/total')"
eximstats -charts -merge -html="index.html" ../[0-1][0-9]/*.html
- # GRAND TOTAL
- folder="${STATDIR}/total"
- [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}"
- cd "${folder}"
+ # GRAND TOTAL (/total/)
+ cdir "total"
eximstats -charts -merge -html="index.html" ../20[0-9][0-9]/[0-1][0-9]/*.html
fi