[1919] in Moira

home help back first fref pref prev next nref lref last post

Re: mailhub.sh changes

daemon@ATHENA.MIT.EDU (Mark Silis)
Fri Jan 18 18:25:45 2002

Date: Fri, 18 Jan 2002 18:24:42 -0500
From: Mark Silis <mark@MIT.EDU>
To: Garry Zacheiss <zacheiss@MIT.EDU>
Cc: Mark Silis <mark@MIT.EDU>, moiradev@MIT.EDU, postmaster@MIT.EDU
Message-ID: <20020118232442.GA781@I-fear-reorgs.MIT.EDU>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <200201182252.RAA24749@sweet-transvestite.mit.edu>

Yeah I was torn, since honestly none of the error strings are the clear "right"
thing. That said, it seems resonable so here you go:

-- Mark

Index: mailhub.sh
===================================================================
RCS file: /afs/athena/astaff/project/moiradev/repository/moira/gen/mailhub.sh,v
retrieving revision 1.10
diff -u -r1.10 mailhub.sh
--- mailhub.sh	2001/11/24 00:08:46	1.10
+++ mailhub.sh	2002/01/18 23:19:58
@@ -1,19 +1,53 @@
 #!/bin/sh
-PATH=/bin:/usr/ucb:/usr/bin
-root=/usr/local/sendmail
+#
+# $Header$
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/athena/bin:/usr/local/bin
+export PATH
+
+if [ -d /var/athena ] && [ -w /var/athena ]; then
+    exec >/var/athena/moira_update.log 2>&1
+else
+    exec >/tmp/moira_update.log 2>&1
+fi
 
+# The following exit codes are defined and MUST BE CONSISTENT with
+# error codes the library uses:
 MR_MKCRED=47836474
+MR_MISSINGFILE=47836473
+MR_NOCRED=47836470
+
+root=/usr/local/sendmail
+
+if [ -r $root/etc/aliases.new ]; then
+    chmod 644 $root/etc/aliases.new
+else
+    exit $MR_MISSINGFILE
+fi
 
-cat $root/etc/aliases.legacy > $root/etc/aliases.tmp
-cat $root/etc/aliases.new >> $root/etc/aliases.tmp
-cat $root/etc/aliases.local >> $root/etc/aliases.tmp
-mv $root/etc/aliases.tmp $root/etc/aliases.new
+# Play it safe and be sure we have reasonable data
+olines=`wc -l $root/etc/aliases |  awk '{print $1}'`
+nlines=`wc -l $root/etc/aliases.new | awk '{print $1}'`
+diff=`expr $nlines - $olines`
+thresh=`expr $nlines / 10`
+
+# Catch the zero case
+if [ $nlines -eq 0 ]; then
+    logger -p mail.error -t mailhub.sh "Recieved empty aliases file, aborting."
+    exit $MR_MISSINGFILE
+fi
+
+# If its a greater than 10% shift bomb out to be safe
+if [ $diff -gt $thresh ]; then
+    logger -p mail.error -t mailhub.sh "Alias changes threshold exceeded, aborting."
+    exit $MR_NOCRED
+fi
 
 cp /dev/null $root/etc/aliases.new.db
 
 $root/sbin/sendmail -bi -oA$root/etc/aliases.new
 if [ $? != 0 ]; then
-	exit $MR_MKCRED
+    exit $MR_MKCRED
 fi
 
 kill `ps -ef | grep "sendmail" | egrep -v "grep|mqueue.stall" | awk '{print $2}'`
@@ -24,15 +58,13 @@
 mv $root/etc/aliases.new $root/etc/aliases
 mv $root/etc/aliases.new.db $root/etc/aliases.db
 
-cd /usr/spool/mqueue
-rm -f xf* tf* lf* nf*
-
-#$root/sbin/sendmail -bd
-#$root/sbin/sendmail -q20m
-
 sh /etc/init.d/sendmail start
 
+# Make sure the sendmail daemons are indeed running
+ps -ef | grep sendmail | grep -v grep > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+    exit $MR_MKCRED
+fi
+
 rm -f $0
 exit 0
-
-# $Header: /afs/athena/astaff/project/moiradev/repository/moira/gen/mailhub.sh,v 1.10 2001/11/24 00:08:46 zacheiss Exp $


On Fri, Jan 18, 2002 at 05:52:03PM -0500, Garry Zacheiss wrote:
> >> +# Catch the zero case
> >> +if [ $nlines -eq 0 ]; then
> >> +    logger -p mail.error -t mailhub.sh "Recieved empty aliases file,
> >> aborting."
> >> +    exit $MR_MKCRED
> >> +fi
> >> +
> >> +# If its a greater than 10% shift bomb out to be safe
> >> +if [ $diff -gt $thresh ]; then
> >> +    logger -p mail.error -t mailhub.sh "Alias changes threshold
> >> exceeded, aborting."
> >> +    exit $MR_MKCRED
> >> +fi
> 
>    I'd like to see these exit values replaced with $MR_MISSINGFILE and
> $MR_NOCRED, respectively.  I think the error string they correspond to
> will be a little more descriptive of the problem that $MR_MKCRED is.
> 
>    Other than that, it looks good.
> 
> Garry
> 
> 
> 

home help back first fref pref prev next nref lref last post