diff options
author | Dennis Eriksen <d@ennis.no> | 2019-03-01 07:47:00 +0100 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2019-03-01 07:47:00 +0100 |
commit | 7b1955f265a585215190911fe31eb5701cbc83b2 (patch) | |
tree | 5634a7fcd77b44e2ad08acdd0aa7b3be22b59403 | |
parent | do not run this months total on the first - there is no data to run it on yet (diff) | |
download | eximstats-cron-7b1955f265a585215190911fe31eb5701cbc83b2.tar.gz |
moving to double brackets
-rwxr-xr-x | eximstats-cron | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/eximstats-cron b/eximstats-cron index 854a798..8306760 100755 --- a/eximstats-cron +++ b/eximstats-cron @@ -15,26 +15,26 @@ STATDIR="/var/www/eximstats.dnns.no" # Daily daily="${STATDIR}/"$(date --date '-1 day' "+%Y/%m/%d.html") -[ -d "$(dirname ${daily})" ] || mkdir -p $(dirname "${daily}") +[[ -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}" +[[ -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" - [ -d "${folder}" ] && rm -f "${folder}"/* || mkdir "${folder}" + [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}" cd "${folder}" files="" n=${1}; - while [ ${n} -gt 0 ]; + while [[ ${n} -gt 0 ]]; do day="${STATDIR}/"$(date --date "-${n} days" "+%Y/%m/%d.html") - [ -f "${day}" ] && files+="${day} " + [[ -f "${day}" ]] && files+="${day} " let n--; done; eximstats -charts -merge -html="index.html" ${files} @@ -49,31 +49,31 @@ stats_for_last_n_days 7 stats_for_last_n_days 30 # update this months total, unless it is the first of the month -if [ $(date '+%d') != 01 ]; then +if [[ $(date '+%d') != 01 ]]; then folder="${STATDIR}/"$(date "+%Y/%m/total") - [ -d "${folder}" ] && rm -f "${folder}"/* || mkdir "${folder}" + [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}" cd "${folder}" 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 +if [[ $(date '+%d') == 01 ]]; then # Monthly folder="${STATDIR}/"$(date --date '-1 day' "+%Y/%m/total") - [ -d "${folder}" ] && rm -f "${folder}"/* || mkdir "${folder}" + [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}" cd "${folder}" eximstats -charts -merge -html="index.html" ../*.html # Yearly folder="${STATDIR}/"$(date --date '-1 day' "+%Y/total") - [ -d "${folder}" ] && rm -f "${folder}"/* || mkdir "${folder}" + [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}" cd "${folder}" eximstats -charts -merge -html="index.html" ../[0-1][0-9]/*.html # GRAND TOTAL folder="${STATDIR}/total" - [ -d "${folder}" ] && rm -f "${folder}"/* || mkdir "${folder}" + [[ -d "${folder}" ]] && rm -f "${folder}"/* || mkdir "${folder}" cd "${folder}" eximstats -charts -merge -html="index.html" ../20[0-9][0-9]/[0-1][0-9]/*.html fi |