128263Spst#!/bin/sh
228263Spst#
350472Speter# $FreeBSD: releng/10.3/etc/periodic/daily/440.status-mailq 208060 2010-05-14 04:53:57Z dougb $
428263Spst#
528263Spst
661981Sbrian# If there is a global system configuration file, suck it in.
761981Sbrian#
861981Sbrianif [ -r /etc/defaults/periodic.conf ]
961981Sbrianthen
1061981Sbrian    . /etc/defaults/periodic.conf
1161981Sbrian    source_periodic_confs
1261981Sbrianfi
1332615Swosch
1461981Sbriancase "$daily_status_mailq_enable" in
1561981Sbrian    [Yy][Ee][Ss])
1665843Sbrian	if [ ! -x /usr/bin/mailq ]
1761981Sbrian	then
1865843Sbrian	    echo '$daily_status_mailq_enable is set but /usr/bin/mailq' \
1965843Sbrian		"isn't executable"
2065843Sbrian	    rc=2
2165843Sbrian	else
2261981Sbrian	    echo ""
2361981Sbrian	    echo "Mail in local queue:"
2461981Sbrian
2565843Sbrian	    rc=$(case "$daily_status_mailq_shorten" in
2661981Sbrian		[Yy][Ee][Ss])
2796160Sbrian		    mailq |
28107674Skeramida			egrep -e '^[[:space:]]+[^[:space:]]+@' |
2961981Sbrian			sort |
3061981Sbrian			uniq -c |
3161981Sbrian			sort -nr |
32156435Smatteo			awk '$1 >= 1 {print $1, $2}';;
3361981Sbrian		*)
3461981Sbrian		    mailq;;
35156435Smatteo	    esac | tee /dev/stderr |
36156435Smatteo	    egrep -v '(mqueue is empty|Total requests)' | wc -l)
37156435Smatteo	    [ $rc -gt 0 ] && rc=1 || rc=0
3894342Sgshapiro
3994342Sgshapiro	    case "$daily_status_include_submit_mailq" in
4094342Sgshapiro	    [Yy][Ee][Ss])
4194342Sgshapiro		if [ -f /etc/mail/submit.cf ]
4294342Sgshapiro		then
4394342Sgshapiro		    echo ""
4494342Sgshapiro		    echo "Mail in submit queue:"
4594342Sgshapiro
46155422Smatteo		    rc_submit=$(case "$daily_status_mailq_shorten" in
4794342Sgshapiro			[Yy][Ee][Ss])
4896160Sbrian			    mailq -Ac |
49107674Skeramida				egrep -e '^[[:space:]]+[^[:space:]]+@' |
5094342Sgshapiro				sort |
5194342Sgshapiro				uniq -c |
5294342Sgshapiro				sort -nr |
53156435Smatteo				awk '$1 >= 1 {print $1, $2}';;
5494342Sgshapiro			*)
5594342Sgshapiro			    mailq -Ac;;
56156435Smatteo		    esac | tee /dev/stderr |
57156435Smatteo		    egrep -v '(mqueue is empty|Total requests)' | wc -l)
58156435Smatteo		    [ $rc_submit -gt 0 ] && rc=1
5994342Sgshapiro		fi;;
6094342Sgshapiro	    esac
6161981Sbrian	fi;;
62208060Sdougb
6365843Sbrian    *)  rc=0;;
6461981Sbrianesac
6565843Sbrian
6665843Sbrianexit $rc
67