marty.net 1001 Postcards Love Love Love Meep Meep ZenZodiac DailyQuotation

YOU ARE HERE:
Simple script for logfile junkies

HOME

CPSHOP|

|

|

EMAIL MARTY
  marty.net message board
  « Simple script for logfile junkies »
Welcome, Guest. Please Login or Register.
12/15/17 at 10:12:55
Home Help Search Login Register
   marty.net message board
   About cpshop
   Tutorials
   Simple script for logfile junkies
(Moderator: Marty)
Pages: 1 Reply Notify of replies Send the topic Print 
   Author  Topic: Simple script for logfile junkies  (Read 1831 times)
James
Green Dragon
*

Posts: 9



Go Scots!
   

E-Mail
Simple script for logfile junkies
« on: 03/27/04 at 08:13:49 »
Reply with quote Modify message

Are you a logfile junkie like myself? Then this short script is for you. The purpose of the script is to show the last "n" lines of the log file, commonly referred to as the "tail" and uses the tail function in unix/linux. It breaks each line up into it's individual components, and displays them in a table.

I'm not sure how cpshop works for non-premium shops, but on mine for the sections the logfile doesn't display the name, but a store.###### format. Since this is meaningless to me, I included a simple way to translate that to human readable form for this script. (There probably is a better way to do this with arrays, but I'm not that talented in perl yet). There are comments in the code telling you how to turn off translation and set variables.

To install, just upload to your cp directory and change permissions to 755 (read & execute), then load up in your browser.

***BEGIN CODE***
#!/usr/bin/perl
# change to your perl dir...

# Logfile change as necessary
$ logfile = "cpshop.cgi.2004.03.log";

# Number of lines to show...
$lines = 50;

# Translate page ID's to human readable form
# Add more as necessary
# Change to anything other than YES to not translate.
$translate = "YES"
$1 = "store.123456";
$1t = "Section 1";
$2 = "store.223456";
$2t = "Section 2"

print "Content-type: text/html\n\n";
print <<ENDHTML;

<html>
<body>
Last $lines lines...
<br><br>
<table width="100%" border="1" cellspacing="0" cellpadding="5">
<tr>
<td>Date</td>
<td>IP Address</td>
<td>Section</td>
<td>Page2?</td>
<td>Product</td>
<td>Referrer</td>
</tr>

ENDHTML

@tail = `tail -$lines cplogs/$logfile` ;

foreach $tline (@tail) {
chop($line);
($date,$ip,$page1,$page2,$page3,$refer)=split(/\|/,$tline);

if ($translate eq "YES") {
print "<tr><td>$date</td><td>$ip</td><td nowrap>$page1</td><td>$page2\&nbsp\;</td><td nowrap>$page3\&nbsp\;</td><td>$refer\&nbsp\;</td></tr>";
} else {
print "<tr><td>$date</td><td>$ip</td><td nowrap>";

if ($page1 eq "$1") {
print "$1t";
} elsif ($page1 eq "$2") {
print "$2t";
} else {
print "$page1";
}

# Copy the elsif for any additional page translations you have defined.

}
print "</td><td>$page2\&nbsp\;</td><td nowrap>$page3\&nbsp\;</td><td>$refer\&nbsp\;</td></tr>";


}


print "</table><br><br>The End.</body></html>";

*** END CODE ***
Logged
James
Green Dragon
*

Posts: 9



Go Scots!
   

E-Mail
Re: Simple script for logfile junkies
« Reply #1 on: 03/27/04 at 08:17:43 »
Reply with quote Modify message

Doh, modified my variable but forgot to change it in the post...

Find an replace all instances of without quotes "YES" to "NO" to work correctly. (3 instances, including comment)  
Logged
Pages: 1 Reply Notify of replies Send the topic Print 
Jump to:


marty.net message board (http://www.marty.net/cgi/marty/board/messageboard)

Powered by YaBB 1 Gold - Release (Yet Another Bulletin Board)
Copyright 2000-2001, X-Null. All Rights Reserved.