[1902] in Moira

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

Re: mailhosts.gen

daemon@ATHENA.MIT.EDU (Mark Silis)
Fri Nov 30 15:52:15 2001

Date: Fri, 30 Nov 2001 15:52:08 -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: <20011130155208.A11838@I-fear-reorgs.MIT.EDU>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <200111302043.PAA21566@riff-raff.mit.edu>

Old C habits are hard to break. Ok here it is with your suggested changes.

-- Mark

--- /dev/null	Fri Nov 30 15:49:46 2001
+++ mailhosts.gen	Fri Nov 30 15:49:18 2001
@@ -0,0 +1,54 @@
+#!/moira/bin/perl -Tw
+
+# $Id$
+
+# The following exit codes are defined and MUST BE CONSISTENT with the
+# error codes the library uses:
+$MR_DBMS_ERR = 47836421;
+$MR_OCONFIG = 4783640;
+
+$outfile = '/moira/dcm/mailhosts.out';
+
+use DBI;
+
+$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
+    || exit $MR_DBMS_ERR;
+
+$sth = $dbh->prepare("SELECT f.label, m.address ".
+		     "FROM filesys f, machine m, nfsphys p, serverhosts s ".
+		     "WHERE s.service='POSTOFFICE' AND s.mach_id=f.mach_id ".
+		     "AND f.mach_id=m.mach_id AND f.type='IMAP' ".
+		     "AND f.createflg!=0 AND f.mach_id=p.mach_id ".
+		     "AND f.phys_id=p.nfsphys_id ".
+		     "ORDER BY f.label")
+    || exit $MR_DBMS_ERR;
+$sth->execute || exit $MR_DBMS_ERR;
+
+$tnow = localtime;
+umask 022;
+open(OUT, ">$outfile") || exit $MR_OCONFIG;
+
+print OUT "; MIT Network Host Table\n;\n";
+print OUT "; \t\$Author: \$\n";
+print OUT "; \t\$Date: \$\n";
+print OUT "; \t\$Revision: \$\n;\n";
+print OUT "; Host table generated by Moira at $tnow\n;\n";
+
+while (($label, $address) = $sth->fetchrow_array) {
+    $label =~ s/\.po$//;
+    $label =~ tr/a-z/A-Z/;
+    if (16 - length($label) > 8) {
+	$sp = "\t";
+    }
+    else {
+	$sp = "";
+    }
+    $row = "$label$sp\tIN\tA\t$address\n";
+    $row =~ s/\0//g;;
+    print OUT $row;
+}
+
+close(OUT);
+$dbh->disconnect;
+
+exit 0;

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