Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Parsing Apache Log to Get Most Recent File Access

by enoch (Chaplain)
on Nov 26, 2002 at 19:36 UTC ( #215910=note: print w/replies, xml ) Need Help??

in reply to Parsing Apache Log to Get Most Recent File Access

++'s all around!

cLive ;-)'s solution worked with a couple of minor tweaks. Here is the final working version.

#!/usr/bin/perl use warnings; use strict; use Date::Manip; use vars qw(%ipHash); my $order=0; while(<DATA>) { / ^((\d{1,3}\.){3}\d{1,3}) # grab the IP address into $1 \s\-\s\-\s\[ (\d\d\/\w{3}\/\d\d(\d\d\:){3}\d\d) # grab the date into $3 \s\-\d{4}\]\s"\w{1,4}\s ([\/|\w|\.|_]+) # grab the file path into $5 /x; $ipHash{$1}{'order'} = $order++; $ipHash{$1}{'path'} = $5; $ipHash{$1}{'date'} = $3; $ipHash{$1}{'timestamp'} = &UnixDate($3,"%s"); } for (sort { $ipHash{$a}{'order'} <=> $ipHash{$b}{'order'}; } keys %ipH +ash) { print "$_ => $ipHash{$_}{'date'}\t$ipHash{$_}{'path'}\n"; }
Notice, the only things that were changed from cLive ;-)'s version was the $a's in the final print statement had to be changed to $_, and that the 'date' hash element held the nicely formatted date instead of the Unix timestamp.

Thanks, everyone!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://215910]
[LanX]: oh its negative? ;P
[Discipulus]: my warmest comprehension karlgoethebier ;=(
[Discipulus]: yes LanX.. is so good to be appreciated (I fortunately have a big self estimation that compensate)
[LanX]: you can manipulate a html tree by addressing and replacing so called document objects (DOM) and from my experience the same methods can be used with any XML, though I didn't test all browsers yet
LanX just joking, playing "ego judo"
[marto]: good morning all
[Corion]: Hi marto!
[marto]: the race to the bottom continues, many people lost their job yesterday as a client moves to another outsourcer

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-03-23 09:54 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (285 votes). Check out past polls.