roodawg
asked on
Cherry picking Log File entries
Hi, to begin this is not homework.
I am attempting to delve into a logfiles whose formats are as follows..
xx.xx.153.22 - - [23/Oct/2003:05:42:50 -0700] "GET /img_/misc/ekbh.gif HTTP/1.1" 200 43 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; MSN 8.0; MSN 8.5; MSNbMSNI; MSNmen-us; MSNcIA)" 0
xx.xx.210.61 - - [23/Oct/2003:05:43:40 -0700] "GET /img_/misc/okil.gif HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" 0
My wish is to pull from the logs the date, asset name (ekbh.gif), and the number of times that this asset has been called on that day. In my previous efforts at Perl I've been successful in getting browser info and which OS was used but this has stumped me. Can anyone help?
Thanks.
I am attempting to delve into a logfiles whose formats are as follows..
xx.xx.153.22 - - [23/Oct/2003:05:42:50 -0700] "GET /img_/misc/ekbh.gif HTTP/1.1" 200 43 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; MSN 8.0; MSN 8.5; MSNbMSNI; MSNmen-us; MSNcIA)" 0
xx.xx.210.61 - - [23/Oct/2003:05:43:40 -0700] "GET /img_/misc/okil.gif HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" 0
My wish is to pull from the logs the date, asset name (ekbh.gif), and the number of times that this asset has been called on that day. In my previous efforts at Perl I've been successful in getting browser info and which OS was used but this has stumped me. Can anyone help?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I should have clarified one of those lines.
while (<DATA>) { # log file passed to the script via the __DATA__ section at the end of the script
while (<>) { # log file passed to the script via command line
while (<DATA>) { # log file passed to the script via the __DATA__ section at the end of the script
while (<>) { # log file passed to the script via command line
ASKER
FM, thanks. This is a thing of beauty.
I should have mentioned that the logfiles are in the format of appserver.log.YYYY-MM-DD and reside in directories called appserv01, appserv02, appserv03, etc. My need is to have this script delve into each of the appservers (excluding any of the webserver directories). Oh and let's not for get formatting to a CSV file. As stated before I'm pretty new to all this and have done this in the past usint perl's opendir() and readdir() statements. I don't need code but by your experience is this the way to go?
Thanks
I should have mentioned that the logfiles are in the format of appserver.log.YYYY-MM-DD and reside in directories called appserv01, appserv02, appserv03, etc. My need is to have this script delve into each of the appservers (excluding any of the webserver directories). Oh and let's not for get formatting to a CSV file. As stated before I'm pretty new to all this and have done this in the past usint perl's opendir() and readdir() statements. I don't need code but by your experience is this the way to go?
Thanks
I don't have enough info to say if your approach is the best method but it sounds fine. One thing you may want to look at using is the File::Find module.
http://search.cpan.org/~jhi/perl-5.8.1/lib/File/Find.pm
http://search.cpan.org/~jhi/perl-5.8.1/lib/File/Find.pm
$VAR1 = '24/Oct/2003';
$VAR2 = {
'okil.gif' => 3
};
$VAR3 = '23/Oct/2003';
$VAR4 = {
'ekbh.gif' => 3
};
24/Oct/2003: okil.gif=3
23/Oct/2003: ekbh.gif=3