Hello, I received a script that is supposed to be a perl script, but I do not recognize it as such. I have been working with Perl for a while, but there is certainly A LOT out there that I do not know. This does not look like Perl code to me and I could not get it to compile. Notice, no semi-colons, if statement with 'then' instead of '{', etc. Thanks for taking a look for me:
# 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 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" +>" echo "<html>" echo "<head>" echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=i +so-8859-1\">" echo "<title>Tracking Google Content Ads CGI Script</title>" echo "<style type=\"text/css\">" echo "<!--" echo "td {" echo " font-family: verdana, helvetica, sans-serif;" echo " font-size: 11px;" echo "}" echo "body {" echo " font-family: arial, sans-serif;" echo " font-size: 12px;" echo "}" echo "-->" echo "</style>" echo "</head>" echo "<body bgcolor=\"#ffffff\">" # 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 "<!-- CGI Script by Apogee Web Consulting LLC -->" else echo "<br> $LOG_FILE is not in the Apache combined log format!" echo "<br>Expecting 7 fields split by a \" mark." echo "<br>There are `cat $TMP_COUNT` such fields." echo "<br>Here's the first line of your file:" echo "<hr>" head -1 $LOG_FILE echo "<hr>" echo "</body>" echo "</html>" rm $TMP_COUNT exit fi else echo "<br>$LOG_FILE is not in the Apache combined log format!" echo "</body>" echo "</html>" rm $TMP_COUNT exit fi else echo "<br>$LOG_FILE is not a readable file or does not exist! Try a +gain." echo "</body>" echo "</html>" rm $TMP_COUNT exit fi # NOTE: Comment this informational block out if you like echo "Processing LOG_FILE: <b>`echo $LOG_FILE | awk -F/ '{print $NF}'` +</b> ..." echo "<br>" echo "Length: `wc -l $LOG_FILE |awk '{print $1}'` lines" echo "<br>" echo "Start: `head -5 $LOG_FILE |awk '{print $4,$5}' |grep : |head -1` +" echo "<br>" echo "End: `tail -5 $LOG_FILE |awk '{print $4,$5}' |grep : |tail -1`" # Find hits from Google content ads grep googlesyndication\.com $LOG_FILE \ |awk '{print $1,$7,$11}' |sort -u |grep client= |grep "\&url=" \ > $TMP_CONTENT # Exit if no content ads found if test -s $TMP_CONTENT then echo "<br><h2>Hits from Google Content Ads:</h2>" else echo "<br><br>" echo "<b>No content ads found!</b>" echo "</body>" echo "</html>" rm $TMP_COUNT exit fi # Analyze content ads cat $TMP_CONTENT \ |awk -F\&url= '{print $2}' |awk -F\& '{print $1}' \ |sed 's/\"//g s/\+/ /g s/$/X/ s/%2[Bb]/+/g s/%2[Cc]/,/g s/%2[Dd]/-/g s/%2[Ee]/./g s/%2[Ff]/\//g s/%25/\%/g s/%26/\&/g s/%27/\`/g s/%28/(/g s/%29/)/g s/%40/@/g s/%7[Cc]/|/g s/%3[Ff]/?/g s/%3[Dd]/=/g s/%3[Aa]/:/g' \ > $TMP_SITES # Count hits sort -u $TMP_SITES | \ while read page do echo `grep -c "$page" $TMP_SITES` `echo $page |awk -F\/ '{print $3}' +` $page >> $TMP_CPAGES done # Display content ads echo "<table border=1 cellpadding=5 cellspacing=2>" echo " <tr><td>" echo " <table border=0 cellpadding=0 cellspacing=5>" echo " <tr><td align=center><b>Hits</b></td><td align=center><b>Dom +ain</b></td><td align=center><b>Page Where Content Ad Is (or was) Dis +played</b></td></tr>" sort -n $TMP_CPAGES |sed 's/X$//' \ |awk '{print $1"</td><td>"$2"</td><td><a href=\""$3"\" target=\"_blank +\">"$3"</a></td></tr>"}' \ |sed 's/^/ <tr><td align=right>/' echo " </table>" echo " </td></tr>" echo "</table>" echo "<b>" echo "<br>Total hits: `wc -l $TMP_SITES |awk '{print $1}'`" echo "<br>Unique hits: `wc -l $TMP_CPAGES |awk '{print $1}'`" echo "</b>" # Help Text echo "<br><br><b>How To Use This Information:</b>" echo "<ol>" echo " <li>Click on the page where your Google ad was displayed." echo " <li>If you don't want your ad displayed on the site, copy the +domain and..." echo " <li>Paste the domain into Google's Site Exclusion feature at t +he Campaign level." echo "</ol>" # Copyright 2005 Apogee Web Consulting LLC echo "<br>Copyright &copy; 2005 <a href=\"http://www.apogee-web-consul +ting.com\" target=\"_blank\"><img src=\"http://www.apogee-web-consult +ing.com/images/logo_apogee.jpg\" alt=\"Apogee Web Consulting LLC\" wi +dth=100 height=43 border=0 align=middle></a>" # Text version of copyright # echo "<br><br>Copyright &copy; 2005 <a href=\"http://www.apogee-web- +consulting.com\" target=\"_blank\">Apogee Web Consulting LLC</a>" echo "</body>" echo "</html>" # Clean up rm $TMP_CONTENT rm $TMP_SITES rm $TMP_CPAGES rm $TMP_COUNT

Edited by planetscape - added readmore tags

( keep:0 edit:14 reap:0 )


In reply to Does this look like Perl code? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.