source: trunk/locker/sbin/parallel-find.pl @ 1284

Last change on this file since 1284 was 1284, checked in by mitchb, 13 years ago
Do not let parallel-find skip non-athena-cell lockers We have many users in the sipb cell; our responsibility to them is no different. We need to scan all cells we have credentials for.
  • Property svn:executable set to *
File size: 1.8 KB
RevLine 
[722]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
[724]10(! -e $dump) || die "Output directory exists: $dump";
11system("mkdir", $dump) && die;
[722]12
[729]13use Proc::Queue size => 40, debug => 0, trace => 0;
[722]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
[730]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
[729]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>) {
[730]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";
[729]51    }
52    return 0;
53}
54
[722]55while (<FILE>) {
56    my ($user, $homedir) = /^([^ ]*) (.*)$/;
57    my $f=fork;
58    if(defined ($f) and $f==0) {
[1284]59        if ($homedir !~ m|^/afs/athena| && $homedir !~ m|^/afs/sipb| && $homedir !~ m|^/afs/zone|) {
60            print "ignoring foreign-cell $user $homedir\n";
[729]61            exit(0);
62        }
[722]63        print "$user\n";
[729]64        $ret = find($user, $homedir);
[722]65        sleep rand 1;
[724]66        exit($ret);
[722]67    }
[729]68    1 while waitpid(-1, WNOHANG)>0; # avoids memory leaks in Proc::Queue
[722]69}
Note: See TracBrowser for help on using the repository browser.