##################################################################### # SCRIPT: SS_WebLogParser # # This script is a sample Web Log Parser. It takes a web log file and and # reports pages, hit counts, referrers and referrer counts. # # The name of the file containing the web log is passed using FVA (Forward # Variable Assignment) for variable $logfile. # # The output is written to screen. If your logfile is very large, redirect the # output using > filename.txt when calling the script. # # This script can be stored, and edited as needed, in a file called # SS_WebLogParser.txt. The script can then be called as # # script "SS_WebLogParser.txt" logfile("C:/logs/web/20080820") # ##################################################################### # Declare FVA variables. var str logfile # Get the contents of the log file into a str variable var str content repro $logfile > $content # We keep the page list in the following variable - it has the format of # is the marker for the record, is the marker for the field. var str page_list # We keep the referrer list in the following variable - it has the format of # is the marker for the record, is the marker for the field. var str referrer_list # Parse lines one by one while ( $content <> "") do # Get the next line var str line lex -e "1" $content > $line # Make sure that line is not empty. if ($line <> "") do # The line has the following form. # 1.2.3.4 x y [20/Oct/2008:01:02:03 -0100] "GET xxx HTTP/1.2" 1 2 "yyy" ... # The page URL has the following form "GET xxx " var str page stex -p -c "^GET ^[" $line > $page stex "[^ ^" $page > null # The referrer has the following form "yyy", this is the third double quote in the line var str referrer stex "^\"^3]" $line > null stex -r "]^(\"?)^" $line > $referrer # Is this page already in the page_list ? If so, we will just increment the count. # If not, we will add it and set the count to 1. var str sen_arg set $sen_arg = "^"+$page+"^" if ( { sen $sen_arg $page_list } > 0 ) do # This page is already in page_list. # Create dynamic argument for the stex command. var str stex_arg set $stex_arg = "[^"+$page+"^" # Get the page record. var str page_record stex -p $stex_arg $page_list > $page_record stex "[^^" $page_record > null # Extract the count, which is after . var str count_str stex -p "^^[" $page_record > $count_str # Get numeric count var int count set $count = makeint(str($count_str)) # Increment count set $count = $count+1 # Create the updated page record var str updated_page_record set $updated_page_record = $page+""+makestr(int($count)) # Replace page_record with updated_page_record in page_list var str sal_arg set $sal_arg = "^"+$page_record+"^" sal $sal_arg $updated_page_record $page_list > null done else do # This page is not in the list. Add to the list. set $page_list = $page_list + "" + $page + "1" done endif # Completes if ( { sen $sen_arg $page_list } > 0 ) # The following code is very similar to the above code for page. # Is this referrer already in the referrer_list ? If so, we will just increment the count. # If not, we will add it and set the count to 1. set $sen_arg = "^"+$referrer+"^" if ( { sen $sen_arg $referrer_list } > 0 ) do # This referrer is already in referrer_list. # Create dynamic argument for the stex command. var str stex_arg set $stex_arg = "[^"+$referrer+"^" # Get the referrer record. var str referrer_record stex -p $stex_arg $referrer_list > $referrer_record stex "[^^" $referrer_record > null # Extract the count, which is after . var str count_str stex -p "^^[" $referrer_record > $count_str # Get numeric count var int count set $count = makeint(str($count_str)) # Increment count set $count = $count+1 # Create the updated referrer record var str updated_referrer_record set $updated_referrer_record = $referrer+""+makestr(int($count)) # Replace referrer_record with updated_referrer_record in referrer_list var str sal_arg set $sal_arg = "^"+$referrer_record+"^" sal $sal_arg $updated_referrer_record $referrer_list > null done else do # This referrer is not in the list. Add to the list. set $referrer_list = $referrer_list + "" + $referrer + "1" done endif # Completes if ( { sen $sen_arg $referrer_list } > 0 ) done endif # Completes if ($line <> "") done # completes do after while ( $content <> "") # Print the page_list echo "Pages" while ( { sen "^^" $page_list } > 0 ) sal "^^" "\n" $page_list > null while ( { sen "^^" $page_list } > 0 ) sal "^^" "\t" $page_list > null echo $page_list # Print the referrer_list echo "Referrers" while ( { sen "^^" $referrer_list } > 0 ) sal "^^" "\n" $referrer_list > null while ( { sen "^^" $referrer_list } > 0 ) sal "^^" "\t" $referrer_list > null echo $referrer_list