#!/usr/bin/perl #!/usr/bin/perl @businesses = ( ["\"corp.home.ge.com\"","new_corp_home_ge_com.log"], ["\"scotland.gcf.home.ge.com\"","new_scotland_gcf_hom +e_ge_com.log"], ["\"marketing.ge.com\"","new_marketing_ge_com.log"] + ); $rows = scalar(@businesses); #---------------Code to get todays date ------------------------------ +--------- $today = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tod +ay); $year += 1900; $mon++; if ($mday <10) { $mday = "0$mday"; } if ($mon<10) { $mon = "0$mon"; } $today = $year . $mon . $mday; #---------------Code to get yesterdays date -------------------------- +------------- $yesterday = time() - ( 24 * 60 * 60 ); ($sec1,$min1,$hour1,$mday1,$mon1,$year1,$wday1,$yday1,$isdst1) = local +time($yesterday); $year1 += 1900; $mon1++; if ($mday1 <10) { $mday1 = "0$mday1"; } if ($mon1<10) { $mon1 = "0$mon1"; } $yesterday = $year1 . $mon1 . $mday1; #--------------------------------------------------------------------- +---------- $outfile="consolidatedlog.txt"; open (OUT,">$outfile") or die ("Cud not open the $outfile"); opendir(DIR, "/inside29/urchin/test/logfiles") or die ("couldn't open +igelogs"); while ( defined ($filename = readdir(DIR)) ) { $index = index($filename,$yesterday); if ($index > -1) { $date1 = localtime(); print "The log $filename started at $date1.\n"; open(OLD,"/inside29/urchin/test/logfiles/$filename") || die ("Cud no +t open the $filename"); while (<OLD>) { print OUT $_; } close OLD; $date = localtime(); print "The log $filename ended at $date.\n"; } } closedir (DIR); close OUT; #------------------------------------------------------------- $ct = 0; while ($ct < $rows) { $outfile1 = "/inside29/urchin/test/newfeed/$today-$businesses[$ct][1]" +; $newigebusiness = "$businesses[$ct][0]"; $date2 = localtime(); print "$ct log started for $newigebusiness at $date2\n"; open(OUT,">>$outfile1") || die("Could not open out file!$outfile1"); open(OLD,"consolidatedlog.txt") || die ("Could not open the consolidat +ed file"); while ( <OLD>) { if ((index($_,$newigebusiness))> -1) { print OUT $_; } } close OLD; close OUT; $date3 = localtime(); print "$ct log created for $newigebusiness at $date3\n"; $ct += 1; }
In reply to Reduce the time taken for Huge Log files by pr19939
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |