source: locker/sbin/parallel-find.pl @ 793

Last change on this file since 793 was 730, checked in by price, 17 years ago
parallel-find.pl: do the next few steps too. * for each .scripts-version file, do an fs la and ignore if scripts-security-upd no longer has rlidwk * from each .scripts-version file, grab the version line and include that in the output. Still skips non-Athena-cell lockers. Why those finds hang for me (I still have about fifty finds in uninterruptible wait, hours later, despite attempting kill -9) remains an open problem.
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/perl
2
3# Script to help generate find the .scripts-version files
4
5use lib '/mit/scripts/sec-tools/perl';
6
7open(FILE, "</mit/scripts/sec-tools/store/scriptslist");
8my $dump = "/mit/scripts/sec-tools/store/versions";
9
10(! -e $dump) || die "Output directory exists: $dump";
11system("mkdir", $dump) && die;
12
13use Proc::Queue size => 40, debug => 0, trace => 0;
14use POSIX ":sys_wait_h"; # imports WNOHANG
15
16# this loop creates new childs, but Proc::Queue makes it wait every
17# time the limit (50) is reached until enough childs exit
18
19# Note that we miss things where one volume is inside another if we
20# use -xdev.  May miss libraries stuff.
21
22sub updatable ($) {
23    my $filename = shift;
24    for my $l (`fs la "$filename"`) {
25        return 1 if ($l =~ /^  system:scripts-security-upd rlidwk/);
26    }
27    return 0;
28}
29
30sub version ($) {
31    my $dirname = shift;
32    open my $h, "$dirname/.scripts-version";
33    return (<$h>)[-1];
34}
35
36sub find ($$) {
37    my $user = shift;
38    my $homedir = shift;
39
40    open my $files, "find $homedir/web_scripts -xdev -name .scripts-version 2>/dev/null |";
41    open my $out, ">$dump/$user";
42    while (my $f = <$files>) {
43        chomp $f;
44        $f =~ s!/\.scripts-version$!!;
45        if (! updatable($f)) {
46            print STDERR "not updatable: $f";
47            next;
48        }
49        $v = version($f);
50        print $out "$f:$v";
51    }
52    return 0;
53}
54
55while (<FILE>) {
56    my ($user, $homedir) = /^([^ ]*) (.*)$/;
57    my $f=fork;
58    if(defined ($f) and $f==0) {
59        if ($homedir !~ m|^/afs/athena|) {
60            print "ignoring non-athena-cell $user $homedir\n";
61            exit(0);
62        }
63        print "$user\n";
64        $ret = find($user, $homedir);
65        sleep rand 1;
66        exit($ret);
67    }
68    1 while waitpid(-1, WNOHANG)>0; # avoids memory leaks in Proc::Queue
69}
Note: See TracBrowser for help on using the repository browser.