#!/bin/bash # webaccess - Analyzes an Apache-format access_log file, extracting # useful and interesting statistics. setglobal bytes_in_gb = '1048576' # You will want to change the following to match your own host name # to help weed out internally referred hits in the referrer analysis. setglobal host = '"intuitive.com'" if test $Argc -eq 0 { echo "Usage: $[basename $0] logfile" > !2 exit 1 } if test ! -r $1 { echo "Error: log file $1 not found." > !2 exit 1 } setglobal firstdate = $[head -1 $1 | awk '{print $4}' | sed 's/\[//] setglobal lastdate = $[tail -1 $1 | awk '{print $4}' | sed 's/\[//] echo "Results of analyzing log file $1" echo "" echo " Start date: $[echo $firstdate|sed 's/:/ at /]" echo " End date: $[echo $lastdate|sed 's/:/ at /]" setglobal hits = $[wc -l < $1 | sed 's/[^[:digit:]]//g] echo " Hits: $[nicenumber $hits] (total accesses)" setglobal pages = $[grep -ivE '(.txt|.gif|.jpg|.png)' $1 | wc -l | sed 's/[^[:digit:]]//g] echo " Pageviews: $[nicenumber $pages] (hits minus graphics)" setglobal totalbytes = $[awk '{sum+=$10} END {print sum}' $1] /bin/echo -n " Transferred: $[nicenumber $totalbytes] bytes " if test $totalbytes -gt $bytes_in_gb { echo "($[scriptbc $totalbytes / $bytes_in_gb] GB)" } elif test $totalbytes -gt 1024 { echo "($[scriptbc $totalbytes / 1024] MB)" } else { echo "" } # Now let's scrape the log file for some useful data: echo "" echo "The ten most popular pages were:" awk '{print $7}' $1 | grep -ivE '(.gif|.jpg|.png)' | \ sed 's/\/$//g' | sort | \ uniq -c | sort -rn | head -10 echo "" echo "The ten most common referrer URLs were:" awk '{print $11}' $1 | \ grep -vE "(^\"-\"$|/www.$host|/$host)" | \ sort | uniq -c | sort -rn | head -10 echo "" exit 0