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:
NOINC
)tail
to return the number of records specified in NUMFILES
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: |