1#!/bin/sh 2# 3# $FreeBSD: src/etc/periodic/daily/460.status-mail-rejects,v 1.8.2.5 2002/05/13 21:36:44 brian Exp $ 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_mail_rejects_enable" in 15 [Yy][Ee][Ss]) 16 if [ ! -d /etc/mail ] 17 then 18 echo '$daily_status_mail_rejects_enable is set but /etc/mail' \ 19 "doesn't exist" 20 rc=2 21 elif [ ! -f /var/log/maillog ] 22 then 23 echo '$daily_status_mail_rejects_enable is set but ' \ 24 "/var/log/maillog doesn't exist" 25 rc=2 26 elif [ "$daily_status_mail_rejects_logs" -le 0 ] 27 then 28 echo '$daily_status_mail_rejects_enable is set but ' \ 29 '$daily_status_mail_rejects_logs is not greater than zero' 30 rc=2 31 else 32 echo 33 echo Checking for rejected mail hosts: 34 35 start=`date -v-1d '+%b %d' | sed 's/0\(.\)$/ \1/'` 36 n=$(($daily_status_mail_rejects_logs - 2)) 37 rc=$({ 38 while [ $n -ge 0 ] 39 do 40 if [ -f /var/log/maillog.$n ] 41 then 42 cat /var/log/maillog.$n 43 elif [ -f /var/log/maillog.$n.gz ] 44 then 45 zcat -fc /var/log/maillog.$n.gz 46 elif [ -f /var/log/maillog.$n.bz2 ] 47 then 48 bzcat -fc /var/log/maillog.$n.bz2 49 fi 50 n=$(($n - 1)) 51 done 52 cat /var/log/maillog 53 } | 54 perl -ne "print \"\$2\n\" 55 if (/reject=/ and /^$start.*ruleset=check_\S+,\s+arg1=(<[^@]+@)?([^>,]+).*reject=/o);" | 56 sort -f | uniq -ic | sort -fnr | tee /dev/stderr | wc -l) 57 [ $rc -gt 0 ] && rc=1 58 fi;; 59 60 *) rc=0;; 61esac 62 63exit $rc 64