By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,178 Members | 987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,178 IT Pros & Developers. It's quick & easy.

Analysing simple weblog

P: 2
Hi,

I have few weblogs, example below
65.96.112.177 - - [27/Jan/2007:00:02:10 -0500] "GET /~jking/images/ralph.jpg HTTP/1.1" 200 66196
65.214.44.44 - - [27/Jan/2007:00:02:27 -0500] "GET /~jkabara/Research.htm HTTP/1.0" 200 4696
207.46.98.52 - - [27/Jan/2007:00:02:29 -0500] "GET /~mweiss/new/background.htm HTTP/1.0" 200 3905
207.46.98.52 - - [27/Jan/2007:00:02:35 -0500] "GET /%7Epaws/project_pacer.htm HTTP/1.0" 200 15645
207.46.98.52 - - [27/Jan/2007:00:02:36 -0500] "GET /%7Espring/patterns/node15.html#SECTION00042300000000000000 HTTP/1.1" 200 2641
65.214.44.44 - - [27/Jan/2007:00:02:42 -0500] "GET /~jkling/2110/week04.ppt HTTP/1.0" 200 1914280

Basically... I want to find out, which page did the user start browsing and which page he ended.

The output should be something like
Visitor 65.96.112.177 started browsing at page /~jking/images/ralph.jpg
Visitor 65.96.112.177 ended browsing at page /~jking/images/ralph.jpg
Visitor 65.214.44.44 started browsing at page /~jkabara/Research.htm
Visitor 65.214.44.44 ended browsing at page /~jkling/2110/week04.ppt
.
.
.
.


I wrote the code below assuming that, if the ip doesnt match at the 20th time...it means...the user ended his session. But it aint happening..could someone please help me do this...any other solutions/ideas are welcome

Expand|Select|Wrap|Line Numbers
  1.     open (INF, $logfile);
  2.     read INF, $file, -s INF;
  3.     close INF;
  4.  
  5.     @lines = split /\n/, $file;
  6.  
  7.     foreach (@lines) {
  8.     @values = split / /, $_;
  9.     $visitors{$values[0]}++;
  10.     }
  11.     $maxcount=20;
  12.     $timecounter=250;
  13.     foreach $visitor (keys %visitors)
  14.     {
  15.         $flag = 0 ;
  16.         foreach $logentry (@lines)
  17.         {
  18.             @values = split / /, $logentry;
  19.             if($visitor eq $values[0])
  20.             {
  21.                 $currentpage = $values[6];
  22.                 if($flag==0){
  23.                     print "\n Visitor " . $visitor . " started checking out the page";            
  24.                     print ":     " .$values[6] . " ";
  25.                     $startpage = $values[6];
  26.                     $flag=1;
  27.                     $i=0;    
  28.                     $endpage = $values[6];
  29.                     }
  30.                 else{
  31.                     $endpage = $values[6];
  32.                     }
  33.             }#if 
  34.             else{
  35.                 $i++;
  36.                 }
  37.             if($i > $maxcount) {print "\nLast Page Visited by " . $visitor . " was " .$endpage . " ";last;}                
  38.             print "\ni=" .$i;
  39.         }#for each line
  40.     }#for each visitor
  41.  
Mar 16 '10 #1
Share this Question
Share on Google+
1 Reply


P: 2
Expand|Select|Wrap|Line Numbers
  1. open (INF, $logfile);
  2. read INF, $file, -s INF;
  3. close INF;
  4.  
  5. @lines = split /\n/, $file;
  6.  
  7. foreach (@lines)
  8. {
  9.    @values = split / /, $_;
  10.    $visitors{$values[0]}++;
  11.    if ($visitors{$values[0]} == 1 )
  12.    {
  13.       # Get starting web page
  14.       $report{$values[0]}[0] = "$values[6]";
  15.       # When a user start browsing
  16.       # considering this will be a first page as well as endpage
  17.       $report{$values[0]}[1] = "$values[6]";  
  18.    }
  19.    else
  20.    {
  21.      # Get last web page
  22.      $report{$values[0]}[1] = $values[6];   
  23.    }
  24. }
  25.  
  26. foreach my $key (keys %report)
  27. {
  28.   for my $i (0 .. 1 ) ## 0 -> For starting page 1-> For ending page
  29.   {
  30.     print "\n\nVisitor $key started browsing at page $report{$key}[$i]" if ($i == 0);
  31.     print "\nVisitor $key ended browsing at page $report{$key}[$i]" if ($i == 1);
  32.   }
  33. }
  34.  
Mar 16 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.