# Specify where the Apache log file resides
# NOTE: Change this for your server
LOG_FILE="/var/log/httpd/access_log"
# NOTE: Change this if you don't have access to /tmp
TMP_DIR=/tmp
# Output http header info
echo "Content-type: text/html"
echo
# Output http body (an html document)
echo ""
echo ""
echo "
"
echo ""
echo "Tracking Google Content Ads CGI Script"
echo ""
echo ""
echo ""
# Use tmp files to process the data
sid=`date +%H%M%S`
TMP_COUNT=$TMP_DIR/count_$sid.txt
TMP_CONTENT=$TMP_DIR/content_$sid.txt
TMP_SITES=$TMP_DIR/sites_$sid.txt
TMP_CPAGES=$TMP_DIR/cpages_$sid.txt
# Make sure file exists
if test -f $LOG_FILE
then
# Simple check to verify it's an Apache combined log file
# count.txt file should have only 1 line that reads "7"
head -5 $LOG_FILE |awk -F\" '{print NF}' |sort -u > $TMP_COUNT
if test `wc -l $TMP_COUNT |awk '{print $1}'` -lt 2
then
# need to test for 7 fields (using " as field separator)
if test `cat $TMP_COUNT` -eq 7
then
# File is ok to process
echo ""
else
echo "
$LOG_FILE is not in the Apache combined log format!"
echo "
Expecting 7 fields split by a \" mark."
echo "
There are `cat $TMP_COUNT` such fields."
echo "
Here's the first line of your file:"
echo "
"
head -1 $LOG_FILE
echo "
"
echo ""
echo ""
rm $TMP_COUNT
exit
fi
else
echo "
$LOG_FILE is not in the Apache combined log format!"
echo "