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