Latest Page Views


I got this idea from a nice script by Randal Schwartz to show latest views to a page. Once in awhile, I like to see what's the latest content viewed on a website, without futzing with logfiles on a terminal.

The article "Browsing Web Logs Quickly" uses a small shell script to check out latest viewed files. I figured I could use this script as a service, then write a small wrapper around it to make it fit my web needs.

So, a small script was made to call the browselog script, then filter the output and return a user defined number of records.

Script overview:

     1	#!/bin/sh
     2	
     3	# CONFIG BEGIN
     4	
     5	# specify lists like this:
     6	
     7	# NOINC="(.htm|.jpg)"
     8	
     9	NOINC="(.css|.class|.js|.cgi|.xsl|.gz|.ico)"
    10	NUMFILES=5
    11	MYFILTER="/usr/local/webtools/browselog"
    12	
    13	# CONFIG END
    14	
    15	MYDATE=`date | awk '{print $3 "/" $2 "/" $6}'`
    16	
    17	$MYFILTER $MYDATE | egrep -v $NOINC | tail -${NUMFILES} | \
        awk '{print "<LI><A HREF=\"" $7 "\">" $7 "</A> on " $4 "]</LI><BR>"}'
     

By invoking this in your .shtml file (ensuring your server understands server-side includes):

      <HTML>
       <HEAD>
        <TITLE>latest viewed content on my website</TITLE>
       </HEAD>
       <BODY>
       <H1>latest viewed content on my website</H1>
       <HR NOSHADE>
      
       <P>
        The most recent pages viewed are: <BR>
        <!--#exec cmd="/www/cgi-bin/latestViewed.cgi"-->
       <P>
 
        <BR>
       </BODY>
      </HTML>
     

...you'll end up with a web-friendly formatted list like this:

The most recent pages viewed are:

  • /about/webstats/2001/04/SearchEngineAnalysis.html on [13/Aug/2001:17:33:50]

  • /gis/project/outline/tasks.htm on [13/Aug/2001:17:37:57]

  • /about/webstats/2001/02/PageReferralsforresume.html on [13/Aug/2001:17:47:44]

  • /about/webstats/2001/02/index.html on [13/Aug/2001:17:49:10]

  • /gis/vector/assignmentOne/ on [13/Aug/2001:18:07:40]