]> andersk Git - moira.git/blob - gen/mailhosts.gen
310021131db9982047667e0ddea957f1ac9fcee8
[moira.git] / gen / mailhosts.gen
1 #!/moira/bin/perl -Tw
2
3 # $Id$
4
5 # The following exit codes are defined and MUST BE CONSISTENT with the
6 # error codes the library uses:
7 $MR_DBMS_ERR = 47836421;
8 $MR_OCONFIG = 4783640;
9
10 $outfile = '/moira/dcm/mailhosts.out';
11
12 use DBI;
13
14 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
15     || exit $MR_DBMS_ERR;
16
17 $sth = $dbh->prepare("SELECT f.label, m.name ".
18                      "FROM filesys f, machine m, nfsphys p, serverhosts s ".
19                      "WHERE s.service='POSTOFFICE' AND s.mach_id=f.mach_id ".
20                      "AND f.mach_id=m.mach_id AND f.type='IMAP' ".
21                      "AND f.createflg!=0 AND f.mach_id=p.mach_id ".
22                      "AND f.phys_id=p.nfsphys_id ".
23                      "ORDER BY f.label")
24     || exit $MR_DBMS_ERR;
25 $sth->execute || exit $MR_DBMS_ERR;
26
27 $tnow = localtime;
28 umask 022;
29 open(OUT, ">$outfile") || exit $MR_OCONFIG;
30
31 print OUT "; MIT Network Host Table\n;\n";
32 print OUT "; \t\$" . "Author:" . " \$\n";
33 print OUT "; \t\$" . "Date:" . " \$\n";
34 print OUT "; \t\$" . "Revision:" . " \$\n";
35 print OUT "; Host table generated by Moira at $tnow\n;\n";
36
37 while (($label, $name) = $sth->fetchrow_array) {
38     $label =~ s/\.po$//;
39     $label =~ tr/a-z/A-Z/;
40     $name =~ tr/a-z/A-Z/;
41
42     if (16 - length($label) > 8) {
43         $sp = "\t";
44     }
45     else {
46         $sp = "";
47     }
48     $row = "$label$sp\tIN\tCNAME\t$name.\n";
49     $row =~ s/\0//g;;
50     print OUT $row;
51 }
52
53 close(OUT);
54 $dbh->disconnect;
55
56 exit 0;
This page took 0.051151 seconds and 3 git commands to generate.