#!/usr/bin/perl $reportdir="/report/csv"; @basedirs=qw; foreach $starting_point (@basedirs){ &recursion("$starting_point"); } sub recursion { my $dir=shift; opendir(DIR, $dir) or return; my @contents=map "$dir/$_",sort grep !/^\.\.?$/,readdir DIR; closedir DIR; foreach (@contents) { next unless !-l && -e; &recursion($_); next if -d | /gz/ | ! /20050412/; if (/12\/(\w+(-\w+)??)(-\d)??-20050412/){push(@list,$1);} } } sub seek{ my $directory=shift; opendir(LIFT, $directory) or return; my @closed=map "$directory/$_",sort grep !/^\.\.?$/,readdir LIFT; closedir LIFT; foreach (@closed){ next unless !-l && -e; &seek($_); next if -d | ! /$indiv/; next if ! /20050412/; push(@cleaned,$_); } } sub gather{ `tar xvf /var/config/$uniqu-config.20050412 gateway.cf`; $config_fw="gateway.cf"; open (GATEWAY,"$config_fw") || die "cant open gateway:$!"; while (){ if (/\#(\d+)/) { $rule="$1"; $hash{$rule}="0"; } } close GATEWAY; unlink ($config_fw); } %seen=(); @uniqu=grep { ! $seen{$_} ++ } @list; foreach $uniqu (@uniqu){ %hash=(); if ($uniqu=~/tias/){$tune="/log";$indiv="$uniqu-";} else {$tune="/log2";$indiv="$uniqu-";} open(REPORT,">$reportdir/$uniqu-20050412"); &seek($tune); &gather; for $i (@cleaned){ open (FH,"$i"); while (){ if (/rule\=(\d+)/){ ($rule)="$1"; $hash{$rule}=($hash{$rule}+1); } } } foreach $rule (sort{$a<=>$b} keys(%hash)){ print REPORT "$uniqu,12/04/2005,$rule,$hash{$rule}\n"; } close REPORT; close FH; }