1 | #!/moira/bin/perl -Tw |
---|
2 | |
---|
3 | # $Id: tsm.gen 3956 2010-01-05 20:56:56Z 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 | |
---|
9 | $ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin"; |
---|
10 | |
---|
11 | $outdir = '/moira/dcm/tsm'; |
---|
12 | umask 022; |
---|
13 | |
---|
14 | use DBI; |
---|
15 | |
---|
16 | $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira") |
---|
17 | || exit $MR_DBMS_ERR; |
---|
18 | |
---|
19 | $sth0 = $dbh->prepare("SELECT l.list_id, m.name " . |
---|
20 | "FROM list l, machine m, serverhosts sh " . |
---|
21 | "WHERE sh.value3 = l.name AND sh.service = 'TSM' " . |
---|
22 | "AND m.mach_id = sh.mach_id") || exit $MR_DBMS_ERR; |
---|
23 | $sth0->execute; |
---|
24 | |
---|
25 | while (($root_list_id, $hostname) = $sth0->fetchrow_array) { |
---|
26 | open(OUT, ">$outdir/$hostname"); |
---|
27 | |
---|
28 | $sth = $dbh->prepare("SELECT l.name, l.gid FROM list l " . |
---|
29 | "WHERE l.list_id = " . |
---|
30 | $dbh->quote($root_list_id)) || |
---|
31 | exit $MR_DBMS_ERR; |
---|
32 | $sth->execute; |
---|
33 | |
---|
34 | while (($name, $gid) = $sth->fetchrow_array) { |
---|
35 | $row = "$name:$gid:"; |
---|
36 | $row =~ s/\0//g; |
---|
37 | print OUT $row; |
---|
38 | $maybecomma = ""; |
---|
39 | } |
---|
40 | |
---|
41 | $sth = $dbh->prepare("SELECT u.login FROM users u, imembers i " . |
---|
42 | "WHERE i.list_id = " . $dbh->quote($root_list_id) . |
---|
43 | "AND i.direct = 1 " . |
---|
44 | "AND i.member_type = 'USER' " . |
---|
45 | "AND u.users_id = i.member_id") || exit $MR_DBMS_ERR; |
---|
46 | $sth->execute; |
---|
47 | |
---|
48 | while (($login) = $sth->fetchrow_array) { |
---|
49 | $row = "$maybecomma$login"; |
---|
50 | $row =~ s/\0//g; |
---|
51 | print OUT $row; |
---|
52 | $maybecomma = ","; |
---|
53 | } |
---|
54 | |
---|
55 | $row = "\n"; |
---|
56 | $row =~ s/\0//g; |
---|
57 | print OUT $row; |
---|
58 | |
---|
59 | $sth = $dbh->prepare("SELECT l.name, l.gid FROM list l, imembers i " . |
---|
60 | "WHERE i.list_id = " . $dbh->quote($root_list_id) . |
---|
61 | "AND i.member_type = 'LIST' " . |
---|
62 | "AND i.member_id = l.list_id AND i.direct = 1 " . |
---|
63 | "AND l.grouplist = 1 ORDER BY l.name") || exit $MR_DBMS_ERR; |
---|
64 | $sth->execute; |
---|
65 | |
---|
66 | while (($name, $gid) = $sth->fetchrow_array) { |
---|
67 | $sth2 = $dbh->prepare("SELECT UNIQUE i.member_type, i.member_id " . |
---|
68 | "FROM imembers i, list l " . |
---|
69 | "WHERE l.name = " . $dbh->quote($name) . |
---|
70 | "AND i.list_id = l.list_id " . |
---|
71 | "AND (i.member_type = 'USER' " . |
---|
72 | "OR i.member_type = 'STRING')") || |
---|
73 | exit $MR_DBMS_ERR; |
---|
74 | $sth2->execute; |
---|
75 | |
---|
76 | $row = "$name:$gid:"; |
---|
77 | $row =~ s/\0//g; |
---|
78 | print OUT $row; |
---|
79 | $maybecomma = ""; |
---|
80 | |
---|
81 | while (($type, $id) = $sth2->fetchrow_array) { |
---|
82 | if ($type eq "USER") { |
---|
83 | ($member) = $dbh->selectrow_array("SELECT login FROM users " . |
---|
84 | "WHERE users_id = " . |
---|
85 | $dbh->quote($id)) || |
---|
86 | exit $MR_DBMS_ERR; |
---|
87 | } |
---|
88 | elsif ($type eq "STRING") { |
---|
89 | ($member) = $dbh->selectrow_array("SELECT string " . |
---|
90 | "FROM strings " . |
---|
91 | "WHERE string_id = " . |
---|
92 | $dbh->quote($id)) || |
---|
93 | exit $MR_DBMS_ERR; |
---|
94 | } |
---|
95 | $row = "$maybecomma$member"; |
---|
96 | $row =~ s/\0//g; |
---|
97 | print OUT $row; |
---|
98 | $maybecomma = ","; |
---|
99 | } |
---|
100 | |
---|
101 | $row = "\n"; |
---|
102 | $row =~ s/\0//g; |
---|
103 | print OUT $row; |
---|
104 | } |
---|
105 | close(OUT); |
---|
106 | } |
---|
107 | |
---|
108 | $dbh->disconnect; |
---|
109 | |
---|
110 | exit 0; |
---|