#! /usr/bin/perl # # This script converts a MS-IIS4 logfile to the CLF logfile format # which is used by Apache among others. # # Author: Philipp Tobler, mailto:Philipp.Tobler@eurecom.fr # # Description of an IIS logfile, long format: # Software: Microsoft Internet Information Server 4.0 # Version: 1.0 # Fields: date time c-ip cs-username s-sitename s-computername s-ip cs-method # cs-uri-stem cs-uri-query sc-status sc-win32-status sc-bytes cs-bytes # time-taken s-port cs-version cs(User-Agent) cs(Cookie) cs(Referer) # # Description of an IIS logfile, short format: # Software: Microsoft Internet Information Server 4.0 # Version: 1.0 # Fields: date time c-ip cs-username cs-method cs-uri-stem sc-status # sc-bytes cs(User-Agent) cs(Cookie) cs(Referer) # IIS seems to store the time in the current timezone of the server, # but in CLF, the time is stored in UTC +-timezone shift $timezone = "+0200"; unless ($#ARGV == 1) { die("Too few or too many input arguments.\nUsage: $0 "); } $inputfilename=$ARGV[0]; $outputfilename=$ARGV[1]; @months=("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); open(INFILE, "$inputfilename") || die("$inputfilename not found."); open(OUTFILE, ">$outputfilename") || die("$outputfilename not found."); while () { unless (/^\#/) { # skip comments chomp; # uncomment these lines if your server produces the logfiles in the "long" format ($date, $time, $c_ip, $cs_username, $s_sitename, $s_computername, $s_ip, $cs_method, $cs_uri_stem, $cs_uri_query, $sc_status, $sc_win32_status, $sc_bytes, $cs_bytes, $time_taken, $s_port, $cs_version, $cs_User_Agent, $cs_Cookie, $cs_Referer) = split; # uncomment these lines if your server produces the logfiles in the "short" format # ($date, $time, $c_ip, $cs_username, $cs_method, # $cs_uri_stem, $sc_status, $sc_bytes, $cs_User_Agent, $cs_Cookie, # $cs_Referer) = split; @date_clf = split /-/, $date; $date_clf[1] = $months[$date_clf[1]-1]; $cs_User_Agent =~ s/\+/ /g; print OUTFILE "$c_ip - - [$date_clf[2]/$date_clf[1]/$date_clf[0]:$time "; print OUTFILE "$timezone] \"$cs_method $cs_uri_stem $cs_version\" "; print OUTFILE "$sc_status $sc_bytes \"$cs_Referer\" \"$cs_User_Agent\"\n"; } } close (INFILE); close (OUTFILE);