summary refs log tree commit diff
path: root/bin/msmtp-queue-stat
blob: bb83784a4009ff2ad7590c5537676c3fea7e6af1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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"