1#!/bin/sh
2#
3# $FreeBSD: src/etc/periodic/daily/440.status-mailq,v 1.4.2.5 2002/05/14 10:45:56 brian Exp $
4# $DragonFly: src/etc/periodic/daily/440.status-mailq,v 1.2 2003/06/17 04:24:48 dillon Exp $
5#
6
7# If there is a global system configuration file, suck it in.
8#
9if [ -r /etc/defaults/periodic.conf ]
10then
11    . /etc/defaults/periodic.conf
12    source_periodic_confs
13fi
14
15case "$daily_status_mailq_enable" in
16    [Yy][Ee][Ss])
17	if [ ! -x /usr/bin/mailq ]
18	then
19	    echo '$daily_status_mailq_enable is set but /usr/bin/mailq' \
20		"isn't executable"
21	    rc=2
22	else
23	    echo ""
24	    echo "Mail in local queue:"
25
26	    rc=$(case "$daily_status_mailq_shorten" in
27		[Yy][Ee][Ss])
28		    mailq |
29			perl -ne  'print if /^\s+\S+@/' |
30			sort |
31			uniq -c |
32			sort -nr |
33			awk '$1 > 1 {print $1, $2}';;
34		*)
35		    mailq;;
36	    esac | tee /dev/stderr | fgrep -v 'mqueue is empty' | wc -l)
37	    [ $rc -gt 1 ] && rc=1
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=$(case "$daily_status_mailq_shorten" in
47			[Yy][Ee][Ss])
48			    mailq -Ac |
49				perl -ne  'print if /^\s+\S+@/' |
50				sort |
51				uniq -c |
52				sort -nr |
53				awk '$1 > 1 {print $1, $2}';;
54			*)
55			    mailq -Ac;;
56		    esac | tee /dev/stderr | fgrep -v 'mqueue is empty' | wc -l)
57		    [ $rc -gt 1 ] && rc=1
58		fi;;
59	    esac
60	fi;;
61
62    *)  rc=0;;
63esac
64
65exit $rc
66