#!/usr/bin/perl #perl script to format httpd log into delimited database load file # # first parameter is the name of the log file $flname=shift ; # copyright 2000 Martin P. Lurie and Informix Software # NOT supported. Best of luck. # # use associative array to translate the date into # database format $monthtbl {"Jan"}="01"; $monthtbl {"Feb"}="02"; $monthtbl {"Mar"}="03"; $monthtbl {"Apr"}="04"; $monthtbl {"May"}="05"; $monthtbl {"Jun"}="06"; $monthtbl {"Jul"}="07"; $monthtbl {"Aug"}="08"; $monthtbl {"Sep"}="09"; $monthtbl {"Oct"}="10"; $monthtbl {"Nov"}="11"; $monthtbl {"Dec"}="12"; open (WEBLOG, $flname ) || die "can not open weblog file: $!\n"; while () { chop; ##Don't you just love these! $_ =~ /(^.*) (.) (.) (\[)(.*2000\:)(.{8}).*\"GET \/([a-z]*[0-9]*)(.*) HTTP.*\" ([0-9]*) ([0-9]*).*/; $CDATE = $5; chop ($CDATE ); #print "web2datetime ", web2datetime ( $CDATE ) ; $URL="/$7$8"; print "$1|$2|$3|".web2datetime ($CDATE)." $6|$7|/$7$8|$9|$10|".filetype($URL)."|".linkdepth($URL)."|\n"; # debugging tree depth print $URL."|".linkdepth($URL)."\n"; # set up the delimiter string to use shorthand on output printing $Q="\",\""; #print "\"",$lname,$Q,$fname,$Q,$phone,$Q,$extn,$Q,$uid,$Q,$loc,$Q,$dept,"\"\n"; # } sub web2datetime { my($dstr) = @_; $CDATE =~ /(.{2})\/(.{3})\/(.{4})/; return "$3-$monthtbl{$2}-$1"; } sub linkdepth { my($inputurl) = @_ ; my($lndepth) ; my(@spliturl) ; # use translate tr function to find all / $_ = $inputurl ; #print "splitting $inputurl \n"; # @spliturl = split ( /\//, $inputurl ); $lndepth = tr /\//\T/; #print "in sub with $_ \n" ; return ( $lndepth ) ; } sub filetype { my($inputurl) = @_ ; #$_ = $inputurl; #print "$_ \n"; $result = $inputurl =~ /(.*)\.(.*)/; return ( $2 ) ; }