aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2017-06-28 10:41:18 +0200
committerDavid Runge <dave@sleepmap.de>2017-06-28 10:41:18 +0200
commitc5ed2a55b890e9887e6edfe170f2a1a6e416027c (patch)
treeb80b054a389630d8be8a911a6c5be710659e57db
parent76dec5aa28bcfe39bbeb5509e204da193555f922 (diff)
downloaddotfiles-c5ed2a55b890e9887e6edfe170f2a1a6e416027c.tar.gz
dotfiles-c5ed2a55b890e9887e6edfe170f2a1a6e416027c.tar.bz2
dotfiles-c5ed2a55b890e9887e6edfe170f2a1a6e416027c.tar.xz
dotfiles-c5ed2a55b890e9887e6edfe170f2a1a6e416027c.zip
bin/get_mail_stats: Adding range from yesterday to today (-y).
-rwxr-xr-xbin/get_mail_stats31
1 files changed, 19 insertions, 12 deletions
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"
;;