Hi all,
I'm actually try to develop a perl script to make some stats with Apache and IIS log file.
The script is ok but i want to add a system who scan just the date range that the user have give to the program.
Here my script :
Code:
#!/usr/bin/perl
use strict;
system("cls");
print " Log type ?\n\n";
print " 1.Apache\n";
print " 2.IIS\n\n";
my $num = (<STDIN>);
system("cls");
print " Range date ? \n Exemple : 03/Feb/2009 10/Feb/2009)\n\n";
my $num2 = (<STDIN>);
system("cls");
print " Enter the number of the action :\n\n";
print " 1.Hits IP\n";
print " 2.Hits pages \n";
print " 3.Hits Referer\n";
print " 4.Hits Ko\n";
print " 5.Hits browser\n";
print " 6.Quit\n\n";
open(Fichier, "log") || die "Problem : $!";
my($ligne,@ips,$ip,%total,@pages,$page,%total1,@ref,$ref,%total2,@ko,$ko,%total3,@nav,$nav,%total4);
if ($num == "1") {
while (<Fichier>) {
@ips = (split /\s+/)[0];
foreach $ip (@ips) {
$total{$ip}++;
}
@pages = (split /\s+/)[6];
foreach $page (@pages) {
$total1{$page}++;
}
@ref = (split /\s+/)[9];
foreach $ref (@ref) {
$total2{$ref}++;
}
@ko = (split /\s+/)[8];
foreach $ko (@ko) {
$total3{$ko}++;
}
@nav = (split /\s+/)[10];
foreach $nav (@nav) {
$total4{$nav}++;
}
}
}
elsif ($num == "2") {
while (<Fichier>) {
@ips = (split /\s+/)[0];
foreach $ip (@ips) {
$total{$ip}++;
}
@pages = (split /\s+/)[3];
foreach $page (@pages) {
$total1{$page}++;
}
@ref = (split /\s+/)[6];
foreach $ref (@ref) {
$total2{$ref}++;
}
@ko = (split /\s+/)[8];
foreach $ko (@ko) {
$total3{$ko}++;
}
@nav = (split /\s+/)[12];
foreach $nav (@nav) {
$total4{$nav}++;
}
}
}
else {
print "\nInvalid number - bye !\n";
exit;
}
close(Fichier);
my $num1 = (<STDIN>);
if ($num1 == "1") {
&subip();
}
elsif ($num1 == "2") {
&subpage();
}
elsif ($num1 == "3") {
&subref();
}
elsif ($num1 == "4") {
&subko();
}
elsif ($num1 == "5") {
&subnav();
}
else {
print "\nA bientot\n";
exit;
}
sub subip {
foreach $ip (sort keys %total)
{
print "IP : $ip a ete rencontre $total{$ip} fois\n";
}
exit;
}
sub subpage {
foreach $page (sort keys %total1)
{
print "La Page \"$page a ete visitee $total1{$page} fois.\n";
}
exit;
}
sub subref {
foreach $ref (sort keys %total2)
{
print "Le referer $ref a ete vu $total2{$ref} fois.\n";
}
exit;
}
sub subko {
foreach $ko (sort keys %total3)
{
print "Voici le hit des Kilos octets : $ko ko\n";
}
exit;
}
The Apache log have this form :
90.90.90.90 - - [11/Feb/2009:19:45:42 +0100] "GET /index.php" 200 907 "programmingtalk.com" "Mozilla/4.0 (compatible; MSIE 7.0; Windows)"
Have you an idea to proceed ?
Thx for your help and sorry for my english
Have a nice day.