summary refs log tree commit diff
path: root/bin/msmtp-queue-stat
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2026-04-08 13:18:14 +0900
committerRobert Günzler <r@gnzler.io>2026-04-08 13:18:14 +0900
commitb61b58ce2c1371d6f904f108fa7feed3abfbe5c7 (patch)
tree008a5cf54ecbfffb97ddac30e44c8ab224395ab0 /bin/msmtp-queue-stat
parentd4620f3ac119263fee90bd819eadaf84fc8d50b7 (diff)
*
Automated-commit-by: dots
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'bin/msmtp-queue-stat')
-rwxr-xr-xbin/msmtp-queue-stat17
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/msmtp-queue-stat b/bin/msmtp-queue-stat
new file mode 100755
index 0000000..bb83784
--- /dev/null
+++ b/bin/msmtp-queue-stat
@@ -0,0 +1,17 @@
+#!/bin/sh
+set -eu
+
+throttle_by=10
+throttle_cookie=/tmp/throttle.msmtp-queue-stat
+throttle() {
+	last_called=$(stat -c %Y $throttle_cookie 2>/dev/null || printf 0)
+	now=$(date +%s)
+	touch $throttle_cookie
+	if [ $((now - last_called)) -gt $throttle_by ]; then
+		"$@"
+	else
+		false
+	fi
+}
+
+throttle sh -c "msmtpq --q-mgmt -d | grep id= | wc -l | tee $throttle_cookie" || cat "$throttle_cookie"