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

Last change on this file since 729 was 729, checked in by price, 16 years ago
more perl, less shell (for future enhancements) Temporarily I'm also ignoring stuff in e.g. the sipb cell, because for an undiagnosed reason those finds are hanging for me with my root tokens.
  • Property svn:executable set to *
File size: 1.3 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 find ($$) {
23    my $user = shift;
24    my $homedir = shift;
25
26    open my $files, "find $homedir/web_scripts -xdev -name .scripts-version 2>/dev/null |";
27    open my $out, ">$dump/$user";
28    while (my $f = <$files>) {
29        print $out $f;
30    }
31    return 0;
32}
33
34while (<FILE>) {
35    my ($user, $homedir) = /^([^ ]*) (.*)$/;
36    my $f=fork;
37    if(defined ($f) and $f==0) {
38        if ($homedir !~ m|^/afs/athena|) {
39            print "ignoring non-athena-cell $user $homedir\n";
40            exit(0);
41        }
42        print "$user\n";
43        $ret = find($user, $homedir);
44        sleep rand 1;
45        exit($ret);
46    }
47    1 while waitpid(-1, WNOHANG)>0; # avoids memory leaks in Proc::Queue
48}
Note: See TracBrowser for help on using the repository browser.