#!/bin/ksh # Korn shell script to read access_log and print in reverse (i.e. most recent first) echo "Content-type: text/html" echo "" #### BEGIN PRINTING PREAMBLE HTML #### echo ' Show Access Log

' ### END PREAMBLING RAMBLINGS ### FILE=/var/log/httpd/access_log NUM=`echo $QUERY_STRING|awk -F= '{print $2}'` if [ "$NUM" -eq "" ] ;then NUM=100 fi textArray[0]="" # hold text c=0 # counter #ifs="$IFS" #export IFS=' #' #textArray=(`tail -$NUM $FILE`) #export IFS="$ifs" #textArray=${textArray[*]} cat $FILE | grep -v 192.168.1. | grep -v .css | grep -v .js | tail -$NUM | while read line do textArray[c]=$line c=`expr $c + 1` done len=${#textArray[*]} # use for loop to reverse the array for (( i=$len; i>=0; i-- )) do echo "

${textArray[$i]}" done echo '

'