Current location: Hot Scripts Forums » Programming Languages » Perl » Log program


Log program

Reply
  #1 (permalink)  
Old 04-07-09, 11:54 AM
Nicky93 Nicky93 is offline
New Member
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Log program

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.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to pharse a log but fgets not seeing new line scott2500uk PHP 9 06-12-07 02:39 AM
need advice on how i should go about writing this program burning_red_phoenix Everything Java 0 11-06-05 05:46 PM
Specific database program needed rjfoster Script Requests 0 04-24-05 03:10 PM


All times are GMT -5. The time now is 04:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.