source: trunk/third/moira/gen/ca.gen @ 25817

Revision 25817, 1.9 KB checked in by jdreed, 12 years ago (diff)
In moira: * Re-snapshot moira at r4097 to pick up Status 10 (Suspended) (Trac: #1295) * Remove our addusr.1 and namespace.1 in favor of upstreams (Trac: #918) * Build-dep on OpenSSL and pass new configure flag per moira r4091
  • Property svn:executable set to *
Line 
1#!/moira/bin/perl -Tw
2
3# $Id: ca.gen 4097 2013-02-11 14:54:53Z zacheiss $
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 = 47836460;
9
10$outfile = '/moira/dcm/ca.out';
11
12use DBI;
13$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
14    || exit $MR_DBMS_ERR;
15
16# First, let's do people with NFS homedirs, since it's not hard.
17$sth = $dbh->prepare("SELECT n.nfsphys_id, n.dir, m.name ".
18                     "FROM nfsphys n, machine m ".
19                     "WHERE m.mach_id = n.mach_id ".
20                     "ORDER BY n.nfsphys_id") || exit $MR_DBMS_ERR;
21
22$sth->execute || exit $MR_DBMS_ERR;
23
24umask 022;
25open(OUT, ">$outfile") || exit $MR_OCONFIG;
26
27while (($id, $dir, $machname) = $sth->fetchrow_array) {
28    next if ($id == 0);
29    $foo = $dbh->prepare("SELECT u.login, u.fullname ".
30                         "FROM users u, filesys f ".
31                         "WHERE f.label = u.login AND ".
32                         "(u.status = 1 OR u.status = 10) ".
33                         "AND f.phys_id = " . $dbh->quote($id));
34    $first = 1;
35    $foo->execute || exit $MR_DBMS_ERR;
36    while (($login, $fullname) = $foo->fetchrow_array) {
37        if ($first) {
38            $first = 0;
39            $row = "*$machname:$dir\n";
40            $row =~ s/\0//g;
41            print OUT $row;
42        }
43        $row = "$login,$fullname\n";
44        $row =~ s/\0//g;
45        print OUT $row;
46    }
47}
48
49#Now, let's do all the AFS homedirs.  This will take a while longer.
50$sth = $dbh->prepare("SELECT UNIQUE u.login, u.fullname, f.name ".
51                     "FROM users u, filesys f ".
52                     "WHERE f.label = u.login AND ".
53                     "(u.status = 1 OR u.status = 10) ".
54                     "AND f.type = 'AFS' ".
55                     "ORDER BY u.login") || exit $MR_DBMS_ERR;
56
57$sth->execute || exit $MR_DBMS_ERR;
58
59$last = "";
60while (($login, $name, $dir) = $sth->fetchrow_array) {
61    $dir =~ /(\/.*)\//;
62    $path = $1;
63    if ($path ne $last) {
64        $last = $path;
65        $row = "*AFS:$path\n";
66        $row =~ s/\0//g;
67        print OUT $row;
68    }
69    $row = "$login,$name\n";
70    $row =~ s/\0//g;
71    print OUT $row;
72}
73
74close(OUT);
75$dbh->disconnect;
76
77exit 0;
Note: See TracBrowser for help on using the repository browser.