From: zacheiss Date: Wed, 3 Jan 2007 20:31:58 +0000 (+0000) Subject: warehouse DCM now perl, not Pro*C. X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/e4d3125b41ef46c72f0ee0ad293ad7b0323ae4a7 warehouse DCM now perl, not Pro*C. --- diff --git a/gen/Makefile.in b/gen/Makefile.in index 6a4f1111..ecfb5bc2 100644 --- a/gen/Makefile.in +++ b/gen/Makefile.in @@ -32,23 +32,23 @@ LIB_TARGET=libdcm.a OBJS= acl.o boot.o dhcp.o directory.o hesiod.o hosts.o mailhub.o \ ndb.o network.o nfs.o pobox.o postoffice.o print.o \ - warehouse.o winad.o www.o zephyr.o + winad.o www.o zephyr.o CFILES= acl.c boot.c dhcp.c directory.c hesiod.c hosts.c mailhub.c \ ndb.c network.c nfs.c pobox.c postoffice.c print.c \ - warehouse.c winad.c www.c zephyr.c + winad.c www.c zephyr.c TARGET= acl.gen boot.gen dhcp.gen directory.gen hesiod.gen hosts.gen \ mailhub.gen ndb.gen network.gen nfs.gen pobox.gen \ - postoffice.gen print.gen warehouse.gen winad.gen www.gen zephyr.gen + postoffice.gen print.gen winad.gen www.gen zephyr.gen SCRIPTS=access.gen access.sh acl.sh aliases.sh boot.sh ca.gen calendar.gen \ confluence.gen dhcp.sh events.gen events.sh hesiod.sh ip-billing.gen \ ip-billing.sh ldap.gen longjobs.gen longjobs.sh mailhub.sh \ mailman.gen mailman.sh nagios-printers.gen nagios-printers.sh ndb.sh \ nfs.sh null.sh postoffice.sh print.sh sapprint.gen sapprint.sh \ - spwatch.gen warehouse.sh winstats.gen winstats.sh www.sh zephyr.sh \ - install_dirs install_quotas zero_quotas + spwatch.gen warehouse.gen warehouse.sh winstats.gen winstats.sh \ + www.sh zephyr.sh install_dirs install_quotas zero_quotas .SUFFIXES: .pc .gen diff --git a/gen/warehouse.gen b/gen/warehouse.gen new file mode 100755 index 00000000..560b118c --- /dev/null +++ b/gen/warehouse.gen @@ -0,0 +1,34 @@ +#!/usr/athena/bin/perl -Tw +# +# $Id$ +# Generate a database extract from the users table for the MIT Data Warehouse. +$MR_DBMS_ERR = 47836421; +$MR_OCONFIG = 47836460; + +$outfile = '/moira/dcm/warehouse.out'; + +use DBI; + +$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira") || exit $MR_DBMS_ERR; + +$sth = $dbh->prepare("SELECT login, clearid, first, last, middle " . + "FROM users WHERE (status = 1 OR status = 2 OR " . + "status = 5 OR status = 6 OR status = 7 OR status = 9)"); + +$sth->execute || exit $MR_DBMS_ERR; + +umask 022; +open(OUT, ">$outfile") || exit $MR_OCONFIG; + +while (($login, $clearid, $first, $last, $middle) = $sth->fetchrow_array) { + next if (length($clearid) < 2); + next if ($clearid eq "0" || $clearid eq "\0" || $clearid =~ /^.\D/); + $row = "$login\t$clearid\t$first\t$last\t$middle\n"; + $row =~ s/\0//g; + print OUT $row; +} + +close(OUT); +$dbh->disconnect; + +exit 0; diff --git a/gen/warehouse.pc b/gen/warehouse.pc deleted file mode 100644 index 4f8c0a11..00000000 --- a/gen/warehouse.pc +++ /dev/null @@ -1,161 +0,0 @@ -/* $Id$ - * - * This generates a database extract from the users table for the MIT - * Warehouse. - * - * Copyright (C) 1996-1998 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . - */ - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "util.h" - -EXEC SQL INCLUDE sqlca; - -RCSID("$Header$"); - -char *whoami = "warehouse.gen"; -char *db = "moira/moira"; - -#ifndef WAREHOUSE_SUBDIR -#define WAREHOUSE_SUBDIR "warehouse" -#endif - -char warehouse_dir[MAXPATHLEN]; - -int main(int argc, char **argv) -{ - int out = STDOUT_FILENO; - char *outf = NULL, outft[MAXPATHLEN]; - char control_fn[MAXPATHLEN], cmd[256]; - FILE *f; - int records = 0; - EXEC SQL BEGIN DECLARE SECTION; - char login[USERS_LOGIN_SIZE]; - char id[USERS_CLEARID_SIZE], kname[MAX_K_NAME_SZ]; - char fname[USERS_FIRST_SIZE], lname[USERS_LAST_SIZE]; - char middle[USERS_MIDDLE_SIZE]; - int timestamp; - struct { - char login[12]; - char id[12]; - char fname[20]; - char lname[20]; - char middle[20]; - char sig[256]; - } outrec; - EXEC SQL END DECLARE SECTION; - - initialize_sms_error_table(); - - sprintf(warehouse_dir, "%s/%s", DCM_DIR, WAREHOUSE_SUBDIR); - - EXEC SQL CONNECT :db; - - if (argc == 2) - { - outf = argv[1]; - sprintf(outft, "%s/username_id.map", warehouse_dir); - if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) - { - fprintf(stderr, "unable to open %s for output\n", outf); - exit(MR_OCONFIG); - } - } - else if (argc != 1) - { - fprintf(stderr, "usage: %s [outfile]\n", argv[0]); - exit(MR_ARGS); - } - else - outf = NULL; - - /* The following is declarative, not executed, - * and so is dependent on where it is in the file, - * not in the order of execution of statements. - */ - EXEC SQL WHENEVER SQLERROR GOTO sqlerr; - - EXEC SQL DECLARE x CURSOR FOR - SELECT login, clearid, first, last, middle - FROM users - WHERE (status = 1 or status = 2 or status = 5 OR - status = 6 or status = 7 or status = 9); - EXEC SQL OPEN x; - while (1) - { - EXEC SQL FETCH x INTO :login, :id, :fname, :lname, :middle; - if (sqlca.sqlcode) - break; - if (id == 0) - continue; - if (!isdigit(id[1])) - continue; - strtrim(login); - strtrim(id); - strtrim(fname); - strtrim(lname); - strtrim(middle); - memset(&outrec, 0, sizeof(outrec)); - strcpy(outrec.login, login); - strcpy(outrec.id, id); - strcpy(outrec.fname, fname); - strcpy(outrec.lname, lname); - strcpy(outrec.middle, middle); - write(out, &outrec, sizeof(outrec)); - records++; - } - EXEC SQL CLOSE x; - - EXEC SQL COMMIT; - - if (close(out)) - { - perror("close failed"); - exit(MR_CCONFIG); - } - sprintf(control_fn, "%s/username_id.ctl", warehouse_dir); - - f = fopen(control_fn, "w"); - if (!f) - { - perror("creating username_id control file"); - exit(MR_OCONFIG); - } - fprintf(f, "username_id.map --- Moira feed for MIT Data Warehouse\n"); - fprintf(f, "%d records\n", records); - fprintf(f, "%d bytes\n", records * (12 + 12 + 20 + 20 + 20 + 256)); - fprintf(f, "Full feed\n"); - fprintf(f, "Fixed format -- binary\n"); - fclose(f); - if (outf) - { - fprintf(stderr, "Building tar file.\n"); - sprintf(cmd, "(cd %s; tar cf - . ) | compress > %s", - warehouse_dir, outf); - if (system(cmd)) - exit(MR_TAR_FAIL); - } - - exit(MR_SUCCESS); - -sqlerr: - db_error(sqlca.sqlcode); - exit(MR_DBMS_ERR); -} diff --git a/gen/warehouse.sh b/gen/warehouse.sh index 34ac4d99..0bb6e416 100644 --- a/gen/warehouse.sh +++ b/gen/warehouse.sh @@ -1,10 +1,5 @@ #!/bin/sh -# -# -DIR=/warehouse/transfers/moirausr -TAR_FILE=$DIR/moira.tar.Z - -PATH="/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc" +# $Id$ if [ -d /var/athena ] && [ -w /var/athena ]; then exec >/var/athena/moira_update.log 2>&1 @@ -14,26 +9,20 @@ fi # The following exit codes are defined and MUST BE CONSISTENT with the # error codes the library uses: -set MR_MISSINGFILE = 47836473 -set MR_TARERR = 47836476 - -cd $DIR - -echo extracting $TAR_FILE +MR_MISSINGFILE=47836473 -if [ ! -f $TAR_FILE ]; then - exit $MR_MISSINGFILE -fi +PATH="/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc" +OUTFILE=/warehouse/transfers/moirausr/username_id.map.txt -if zcat < $TAR_FILE | tar xvf -; then - echo Extract successful -else - exit $MR_TARERR -fi +# Alert if the output file doesn't exist +test -r $OUTFILE || exit $MR_MISSINGFILE -chmod 640 username_id.* +# Set the perms usefully +chown root $OUTFILE +chgrp 0 $OUTFILE +chmod 644 $OUTFILE -rm -f $0 -echo removed self +# cleanup +test -f $0 && rm -f $0 exit 0