#!/usr/local/bin/perl # Spawn one process per instance of the 'root' script. my $dir = "/backup/oldlogs"; my $startmo=1; my $endmo=1; my $startday=1; my $endday=15; my $year="01"; for ($mo = $startmo ; $mo <= $endmo ; $mo++){ for ($da = $startday ; $da <= $endday ; $da++){ $mon = sprintf("%02.0d",$mo); $day = sprintf("%02.0d",$da); my $file = "$dir/*/$year$mon/logfile.20$year$mon$day*" ; if ($pid = fork) { # parent process push @pids, $pid ; } else { # child process die ("Fork Failed: $!") unless defined $pid ; print ("$file - $mon$day.results.txt\n"); exec("zcat $file |./subcount.plx > foo.$mon$day.results.txt"); } } } sleep 2; print ("Waiting for pids: @pids\n"); foreach $kidpid (@pids) { $deadpid = wait; print ("pid $deadpid finished.\n"); } print ("All pids finished.\n"); exit 0;