xref: /freebsd/usr.sbin/periodic/etc/daily/440.status-mailq (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1#!/bin/sh
2#
3#
4
5# If there is a global system configuration file, suck it in.
6#
7if [ -r /etc/defaults/periodic.conf ]
8then
9    . /etc/defaults/periodic.conf
10    source_periodic_confs
11fi
12
13case "$daily_status_mailq_enable" in
14    [Yy][Ee][Ss])
15	if [ ! -x /usr/bin/mailq ]
16	then
17	    echo '$daily_status_mailq_enable is set but /usr/bin/mailq' \
18		"isn't executable"
19	    rc=2
20	else
21	    echo ""
22	    echo "Mail in local queue:"
23
24	    rc=$(case "$daily_status_mailq_shorten" in
25		[Yy][Ee][Ss])
26		    mailq |
27			egrep -e '^[[:space:]]+[^[:space:]]+@' |
28			sort |
29			uniq -c |
30			sort -nr |
31			awk '$1 >= 1 {print $1, $2}';;
32		*)
33		    mailq;;
34	    esac | tee /dev/stderr |
35	    egrep -v '((Mail |m)queue is empty|Total requests)' | wc -l)
36	    [ $rc -gt 0 ] && rc=1 || rc=0
37
38	    case "$daily_status_include_submit_mailq" in
39	    [Yy][Ee][Ss])
40		if [ -f /etc/mail/submit.cf ] && mailq -Ac >/dev/null 2>&1
41		then
42		    echo ""
43		    echo "Mail in submit queue:"
44
45		    rc_submit=$(case "$daily_status_mailq_shorten" in
46			[Yy][Ee][Ss])
47			    mailq -Ac |
48				egrep -e '^[[:space:]]+[^[:space:]]+@' |
49				sort |
50				uniq -c |
51				sort -nr |
52				awk '$1 >= 1 {print $1, $2}';;
53			*)
54			    mailq -Ac;;
55		    esac | tee /dev/stderr |
56		    egrep -v '(mqueue is empty|Total requests)' | wc -l)
57		    [ $rc_submit -gt 0 ] && rc=1
58		fi;;
59	    esac
60	fi;;
61
62    *)  rc=0;;
63esac
64
65exit $rc
66