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

Last change on this file since 726 was 724, checked in by price, 16 years ago
parallel-find.pl: work on Macs, and handle errors better * in find, use -print and a redirect rather than -fprint, which doesn't exist in the Mac's find * give a real error message when the directory exists, and die when we should
  • Property svn:executable set to *
File size: 1016 bytes
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;
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
22while (<FILE>) {
23    my ($user, $homedir) = /^([^ ]*) (.*)$/;
24    my $f=fork;
25    if(defined ($f) and $f==0) {
26        print "$user\n";
27        my $ret = system("find $homedir/web_scripts -xdev -name .scripts-version -print > $dump/$user 2> /dev/null");
28        sleep rand 1;
29        exit($ret);
30    }
31    while (waitpid(-1, WNOHANG)>0) {
32        $? && die "child exited with error: $?";
33    }; # reaps childs
34}
Note: See TracBrowser for help on using the repository browser.