1 | #!/moira/bin/perl -Tw |
---|
2 | |
---|
3 | # $Id: winstats.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 | $MR_OCONFIG = 47836460; |
---|
9 | |
---|
10 | $ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin"; |
---|
11 | |
---|
12 | $outdir = '/moira/dcm/winstats'; |
---|
13 | $outfile = '/moira/dcm/winstats.out'; |
---|
14 | |
---|
15 | use DBI; |
---|
16 | |
---|
17 | $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira") |
---|
18 | || exit $MR_DBMS_ERR; |
---|
19 | |
---|
20 | umask 022; |
---|
21 | |
---|
22 | # mcntmap table |
---|
23 | $sth = $dbh->prepare("SELECT mach_id, cnt_id FROM mcntmap") |
---|
24 | || exit $MR_DBMS_ERR; |
---|
25 | |
---|
26 | $sth->execute || exit $MR_DBMS_ERR; |
---|
27 | |
---|
28 | open(OUT, ">$outdir/mcntmap") || exit $MR_OCONFIG; |
---|
29 | |
---|
30 | while (($mach_id, $cnt_id) = $sth->fetchrow_array) { |
---|
31 | $row = "$mach_id\t$cnt_id\n"; |
---|
32 | $row =~ s/\0//g; |
---|
33 | print OUT $row; |
---|
34 | } |
---|
35 | close(OUT); |
---|
36 | |
---|
37 | # machine table |
---|
38 | $sth = $dbh->prepare("SELECT m.name, m.mach_id FROM machine m, " . |
---|
39 | "mcntmap mc WHERE m.mach_id = mc.mach_id") |
---|
40 | || exit $MR_DBMS_ERR; |
---|
41 | |
---|
42 | $sth->execute || exit $MR_DBMS_ERR; |
---|
43 | |
---|
44 | open(OUT, ">$outdir/machine") || exit $MR_OCONFIG; |
---|
45 | |
---|
46 | while (($name, $mach_id) = $sth->fetchrow_array) { |
---|
47 | $row = "$name\t$mach_id\n"; |
---|
48 | $row =~ s/\0//g; |
---|
49 | print OUT $row; |
---|
50 | } |
---|
51 | close(OUT); |
---|
52 | |
---|
53 | # containers table |
---|
54 | $sth = $dbh->prepare("SELECT name, cnt_id, list_id, publicflg, description, " . |
---|
55 | "location, contact, acl_type, acl_id, memacl_type, memacl_id, " . |
---|
56 | "modtime, modby, modwith FROM containers") |
---|
57 | || exit $MR_DBMS_ERR; |
---|
58 | |
---|
59 | $sth->execute || exit $MR_DBMS_ERR; |
---|
60 | |
---|
61 | open(OUT, ">$outdir/containers") || exit $MR_OCONFIG; |
---|
62 | |
---|
63 | while (($name, $cnt_id, $list_id, $publicflg, $description, $location, $contact, |
---|
64 | $acl_type, $acl_id, $memacl_type, $memacl_id, $modtime, $modby, $modwith) |
---|
65 | = $sth->fetchrow_array) { |
---|
66 | $row = "$name\t$cnt_id\t$list_id\t$publicflg\t$description\t$location\t$contact\t$acl_type\t$acl_id\t$memacl_type\t$memacl_id\t$modtime\t$modby\t$modwith\n"; |
---|
67 | $row =~ s/\0//g; |
---|
68 | print OUT $row; |
---|
69 | } |
---|
70 | close(OUT); |
---|
71 | |
---|
72 | # generate tar file |
---|
73 | |
---|
74 | system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG; |
---|
75 | |
---|
76 | $dbh->disconnect; |
---|
77 | |
---|
78 | exit 0; |
---|
79 | |
---|