[1491] in Moira
spwatch.gen
daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Tue Mar 28 18:44:28 2000
Message-Id: <200003282344.SAA00399@w20-spare-ultra2.mit.edu>
To: moiradev@MIT.EDU
cc: cfox@MIT.EDU
Date: Tue, 28 Mar 2000 18:44:16 -0500
From: Garry Zacheiss <zacheiss@MIT.EDU>
Currently, there's a cron job on urania that reports on the
status of the 600 SAP printers around campus. Nothing updates the list
of printers this cron job reads in an automated fashion, which makes it
a pain to keep in sync with reality. Here's a dcm to generate the file
for us.
Index: spwatch.gen
===================================================================
RCS file: spwatch.gen
diff -N spwatch.gen
*** /dev/null Tue Mar 28 16:45:16 2000
--- spwatch.gen Tue Mar 28 18:43:43 2000
***************
*** 0 ****
--- 1,33 ----
+ #!/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 = 47836460;
+
+ $outfile = '/moira/dcm/spwatch.out';
+
+ use DBI;
+
+ $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
+ || exit $MR_DBMS_ERR;
+
+ $sth = $dbh->prepare("SELECT p.name, m.name, p.location FROM printers p, ".
+ "machine m WHERE p.type = 'SAP' AND p.mach_id = ".
+ "m.mach_id ORDER BY p.name") || exit $MR_DBMS_ERR;
+
+ $sth->execute || exit $MR_DBMS_ERR;
+
+ umask 022;
+ open(OUT, ">$outfile") || exit $MR_OCONFIG;
+
+ while (($name, $hostname, $location) = $sth->fetchrow_array) {
+ next if $hostname eq "[NONE]";
+ $row = "$name\t$hostname\t$location\n";
+ $row =~ s/\0//g;
+ print OUT $row;
+ }
+
+ close OUT;
+ exit 0;