用perl脚本来读取apache访问日志

前言
    这是我很久以前的写的perl脚本!~ 由于现在很久没用perl了,所以很多已经淡忘了,所以把它放在博客上,每天看看,让自己加深点印象。

#!/usr/bin/perl
#use CGI qw/:standard/;
#my $cgi=new CGI;
print "Pragma: no-cache\n";
print "Cache-control: no-cache\n";
print "Connection: close\n";
print "Content-type: text/html\n\n";
print "<title>test CGI</title>\n";
#print "test suceess\n";
my $filename="/var/log/httpd/access_log";
open (FILE, $filename) or die "Unable to open config";
print <<END;
<table width="100%" border="1" bordercolor="black">
<tr>
<td width="20%">access_IP</td>
<td width="20%">Time</td>
<td width="20%">access_WWW</td>
<td width="20%">System</td>
<td width="20%">Brows</td>
</tr>
<tr>
END
while (<FILE>){
     @temp = split(/ /);  
         # print $temp[0];
         # print "------";
         # print $temp[3];
  if ($temp[3]=~s/^\[/ /)
                         {
                            $temp[3]=$';
    }
                if($temp[11]=~s/\"/ /)
                    {
                     $temp[11]=$';
                    }
print <<END;
<td width="20%">$temp[0]</td>
<td width="20%">$temp[3]</td>
<td width="20%">$temp[6]</td>
<td width="20%">$temp[11]-$temp[14] $temp[15] $temp[16]</td>
<td width="20%">$temp[22]</td>
</tr>
END
}
print <<END;
</table>
END
close FILE;

你可能感兴趣的:(职场,perl,休闲)