#!/usr/bin/perl -w
use File::Basename;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use File::Path;
use File::Copy;
print "Content-type: text/html\r\n";
print "\r\n";
$accessfile = "/var/log/foo/access_log";
open (example7, "/var/log/foo/access_log") || die ("Could not open file. <br> $!");
@cisco = <example7>;
@passwd = split(' ',$new);
open(READER, $accessfile) or die "canot read log:$accessfile:$!";
@LOGFILE = <READER>;
while(<READER>) {
($machine, $date, $time, $tzone, $method, $url, $httpvers, $response, $size) = /([^\s]*) [^\s]* [^\s]* \[([^\:]*)
[^\s]*) ([^\]]*)\] \"([^\s]*) ([^\s]*) HTTP\/([^\"]*)\" (\d*) (\d*)/;
($day, $month, $year) = split('/',$date);
}
foreach $string (sort(@passwd)) {
my $path = "/path/foo/foo/$string/log";
if (! -d $path)
{
mkpath($path,755) or die "Failed to create $path: $!\n";
}
$file = "$string.txt";
if ($path =~ $string) {
foreach $line (sort(@cisco)) {
$append = 0;
if ($append){
open (OUTFILE,">$file"); if ($line =~ $string) {print OUTFILE $line;}
}else{
open (OUTFILE,">>$file"); if ($line =~ $string) {print OUTFILE $line;}
} }
close (OUTFILE);
move($file,$path) or die "Failed to copy $file: $!\n";
}
}
close (example7);