From c5ed2a55b890e9887e6edfe170f2a1a6e416027c Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 28 Jun 2017 10:41:18 +0200 Subject: bin/get_mail_stats: Adding range from yesterday to today (-y). --- bin/get_mail_stats | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'bin') diff --git a/bin/get_mail_stats b/bin/get_mail_stats index dedb04c..f09d198 100755 --- a/bin/get_mail_stats +++ b/bin/get_mail_stats @@ -3,7 +3,8 @@ set -euo pipefail IFS=$'\n\t' -time_frame="" +time_from="" +time_until="tomorrow" postfix_received="" rbl_dropped="" spampd_clean="" @@ -16,33 +17,36 @@ function set_range() { case $1 in "month") - time_frame=$(date --date="last month" -I) + time_from=$(date --date="last month" -I) ;; "week") - time_frame=$(date --date="last week" -I) + time_from=$(date --date="last week" -I) ;; "day") - time_frame=$(date -I) + time_from=$(date -I) ;; + "yesterday") + time_from=$(date --date="yesterday" -I) + time_until="today" esac } function get_stats() { set +e - postfix_received=$(journalctl -S "$time_frame" _EXE=/usr/lib/postfix/bin/smtpd|grep "proxy-accept"| wc -l) - rbl_dropped=$(journalctl -S "$time_frame" -u postfix |grep "Service unavailable"| wc -l) - spampd_clean=$(journalctl -S "$time_frame" -u spampd| grep "clean message"| wc -l) - spampd_spam=$(journalctl -S "$time_frame" -u spampd| grep "identified spam"| wc -l) - sieve_spam=$(journalctl -S "$time_frame" _EXE=/usr/lib/dovecot/dovecot-lda| grep "Spam"| wc -l) - postfix_sent=$(journalctl -S "$time_frame" _EXE=/usr/lib/postfix/bin/smtp |grep "sent"| wc -l) - postgrey_delayed=$(journalctl -S "$time_frame" -u postgrey |grep "reason=new"| wc -l) + postfix_received=$(journalctl -S "$time_from" -U "$time_until" _EXE=/usr/lib/postfix/bin/smtpd|grep "proxy-accept"| wc -l) + rbl_dropped=$(journalctl -S "$time_from" -U "$time_until" -u postfix |grep "Service unavailable"| wc -l) + spampd_clean=$(journalctl -S "$time_from" -U "$time_until" -u spampd| grep "clean message"| wc -l) + spampd_spam=$(journalctl -S "$time_from" -U "$time_until" -u spampd| grep "identified spam"| wc -l) + sieve_spam=$(journalctl -S "$time_from" -U "$time_until" _EXE=/usr/lib/dovecot/dovecot-lda| grep "Spam"| wc -l) + postfix_sent=$(journalctl -S "$time_from" -U "$time_until" _EXE=/usr/lib/postfix/bin/smtp |grep "sent"| wc -l) + postgrey_delayed=$(journalctl -S "$time_from" -U "$time_until" -u postgrey |grep "reason=new"| wc -l) set -e } function print_stats() { - echo "Mail statistics for $(hostname) since $time_frame" + echo "Mail statistics for $(hostname) since $time_from" echo "Received total: $postfix_received" echo "RBL dropped: $rbl_dropped" echo "Delayed: $postgrey_delayed" @@ -62,6 +66,9 @@ case ${@} in "-d") set_range "day" ;; + "-y") + set_range "yesterday" + ;; *) set_range "day" ;; -- cgit v1.2.3-70-g09d2