>-----Original Message-----
>From: Lance Prais [mailto:[EMAIL PROTECTED]]
>Sent: Monday, December 10, 2001 10:08 AM
>To: [EMAIL PROTECTED]
>Subject: question about reading a page to sort information

< SNIP >
>my script need to do this:
>1. call the function to generate the log file---done that
>2. Read through and file and check for values----Lost
>3. If TK_DISP_RUNSTATE is anything other then running or TK_END_TIME is not
>null send out and email to page myself that the process is running---
Little
>help here would be nice but I think I got this down


>If anyone has done something similar to this I would appreciate some help.
>I am sure it is a simple task but I an inexperience and somewhat confused.

Try Perldoc.com, and look under the FAQ, there usualy good information 
there.

I think the commands you will want is

Regular expressions to check and see if the information exist on a line
that you read in, if so the split the line up by using the delimeter or
column locaions.  For example one that I have posted below will prompt for
a word to look for, then return information off of that record where it
is found.  Let me know if you have questions...


John Herbold
IS Specialist/DBA



#! perl -w
use CGI;
my $query = new CGI;
print $query->header;
print $query->start_html("Parse Web Log");
print "<body BACKGROUND=\"/images/backgrounds/blue_sky_fade.jpg\" >";

get_vars();
get_file();
if ($match_count > 0 ) {if ($REC) {view_detail()} else {view_data();} } 
else {$msg="No matches found for $search<BR>$total_count lines searched";
enter_date();}

sub get_vars {
$date   = $query->param('DATE');
$search = $query->param('SEARCH');
$REC    = $query->param('REC');
$search = uc($search);
if ($date) {} else {enter_date();}
$year  = substr($date,2,2);
$month = substr($date,5,2);
$day   = substr($date,8,2);
$logfile = 'ex' . "$year" . "$month" . "$day" . '.log';
}


sub enter_date {
     print "<SCRIPT LANGUAGE='JavaScript'
SRC='/java_scripts/date.html'></script>";
     print "<SCRIPT LANGUAGE='JavaScript'
SRC='/java_scripts/get_current.html'></script>\n";
     print "<TABLE border=0 width=100% height=100%><TR><TD>\n";
     print "<CENTER><FORM ACTION='/cgi_bin2/utilities/parse_web_log.pl' >\n
";
     print "<TABLE BORDER=1>\n";
     print "<TR><TD COLSPAN=2><CENTER><H2>Search Web Logs</TD></TR>";
     print "<TR><TD COLSPAN=2><CENTER>$msg</CENTER></TR>";
     print "<TR><TD><B><CENTER>Date to Search     </CENTER></B>
</TD><TD><input type='TEXT' name='DATE' onBlur='checkdate(this)'
onFocus='get_date(this)'></TD></TR>";
     print "<TR><TD><B><CENTER>String to Look For </CENTER></B>
</TD><TD><input type='TEXT' name='SEARCH' ></TD></TR>";
     print "<TR><TD colspan=2><center><input type=submit name='submit'
value='Go Find It'><center></TD></TR>\n ";
     print "</TD></TR>";
     print "</TABLE>\n";
     print "</FORM>\n ";
     print "</TD></TR></TABLE>\n";
     exit;
}

sub get_file {

$file = "c:/winnt/system32/logfiles/w3svc1/$logfile";
$total_count=0;
$match_count=0;
open(LOGFILE,$file); 
while (LOGFILE) {
     $total_count++; 
     $line = <LOGFILE>;
     if ($line eq "") { last};
     $linetest = uc($line);
     $test = $linetest =~ m"$search";
     if ($test >0) {$match_count++; @LINE[$match_count] = $line;}
}
close(LOGFILE);
}

sub view_data {
     print "<table border=1>";
     $rec=0;               $date = '';               $htime = '';
$c_ip = '';           
     $cs_username = '';    $s_sitename = '';         $s_computername = '';
$s_ip = ''; 
     $s_port = '';         $cs_method = '';          $cs_uri_stem = '';
$cs_uri_query = ''; 
     $sc_status = '';      $sc_win32_status = '';    $sc_bytes = '';
$cs_bytes = ''; 
     $time_taken = '';     $cs_version = '';         $cs_host = '';
$cs_User_Agent = '';
     $cs_Cookie = '';      $cs_Referer = '';

     print "<TR><TD><B><CENTER> Rec </CENTER></B></TD>";
     print "<TD><B><CENTER> Date </CENTER></B></TD>";
     print "<TD><B><CENTER> Time </CENTER></B></TD>";     
     print "<TD><B><CENTER> Client </CENTER></B></TD>";     
     print "<TD><B><CENTER> Client Name </CENTER></B></TD>";     
     print "<TD><B><CENTER> Method </CENTER></B></TD>";     
     print "<TD><B><CENTER> URI </CENTER></B></TD>";     
     print "<TD><B><CENTER> Status </CENTER></B></TD>";
     print "<TD><B><CENTER> Win32 Status  </CENTER></B></TD>";
     print "<TD><B><CENTER> SC Bytes </CENTER></B></TD>";
     print "<TD><B><CENTER> CS Bytes </CENTER></B></TD>";
     print "<TD><B><CENTER> Time Taken </CENTER></B></TD>";

     
     while ($rec <= $match_count) {
        $rec++;
        ($date, $htime, $c_ip, $cs_username, $s_sitename, $s_computername,
$s_ip, $s_port, $cs_method, $cs_uri_stem, $cs_uri_query, $sc_status,
$sc_win32_status, $sc_bytes, $cs_bytes, $time_taken, $cs_version, $cs_host,
$cs_User_Agent, $cs_Cookie, $cs_Referer) 
        = split(m"\s",@LINE[$rec]);
        print "<TR><TD><A
HREF=\"/CGI_BIN2/utilities/parse_web_log.pl?DATE=$date&SEARCH=$search&REC=$r
ec\">$rec</A></TD>";
        print "<TD>$date </TD>";     
        print "<TD> $htime </TD>";     
        print "<TD> $c_ip </TD>";     
        print "<TD> $cs_username </TD>";     
        print "<TD> $cs_method </TD>";     
        print "<TD> $cs_uri_stem </TD>";     
        print "<TD> $sc_status </TD>";
        print "<TD> $sc_win32_status  </TD>";
        print "<TD> $sc_bytes </TD>";
        print "<TD> $cs_bytes </TD>";
        print "<TD> $time_taken </TD>";
        }
     print "</table>";
exit;   
}

sub view_detail {
     print "<table border=1>";
     ($date, $htime, $c_ip, $cs_username, $s_sitename, $s_computername,
$s_ip, $s_port, $cs_method, $cs_uri_stem, $cs_uri_query, $sc_status,
$sc_win32_status, $sc_bytes, $cs_bytes, $time_taken, $cs_version, $cs_host,
$cs_User_Agent, $cs_Cookie, $cs_Referer) 
        = split(m"\s",@LINE[$REC]);
        print "<TR><TD><CENTER><B>Date               </CENTER></B></TD><TD>
$date </TD></TR>";     
        print "<TR><TD><CENTER><B>Time               </CENTER></B></TD><TD>
$htime </TD></TR>";     
        print "<TR><TD><CENTER><B>Client             </CENTER></B></TD><TD>
$c_ip </TD></TR>";     
        print "<TR><TD><CENTER><B>User               </CENTER></B></TD><TD>
$cs_username </TD></TR>";     
        print "<TR><TD><CENTER><B>Site               </CENTER></B></TD><TD>
$s_sitename </TD></TR>";     
        print "<TR><TD><CENTER><B>Server             </CENTER></B></TD><TD>
$s_computername </TD></TR>";     
        print "<TR><TD><CENTER><B>Server IP          </CENTER></B></TD><TD>
$s_ip </TD></TR>";     
        print "<TR><TD><CENTER><B>Server Port        </CENTER></B></TD><TD>
$s_port </TD></TR>";     
        print "<TR><TD><CENTER><B>Method             </CENTER></B></TD><TD>
$cs_method </TD></TR>";     
        print "<TR><TD><CENTER><B>STEM               </CENTER></B></TD><TD>
$cs_uri_stem </TD></TR>";     
        print "<TR><TD><CENTER><B>Query              </CENTER></B></TD><TD>
$cs_uri_query </TD></TR>";
        print "<TR><TD><CENTER><B>Status             </CENTER></B></TD><TD>
$sc_status </TD></TR>";
        print "<TR><TD><CENTER><B>Win32 Status       </CENTER></B></TD><TD>
$sc_win32_status  </TD></TR>";
        print "<TR><TD><CENTER><B>S -> C Bytes       </CENTER></B></TD><TD>
$sc_bytes </TD></TR>";
        print "<TR><TD><CENTER><B>C -> S Bytes       </CENTER></B></TD><TD>
$cs_bytes </TD></TR>";
        print "<TR><TD><CENTER><B>Time               </CENTER></B></TD><TD>
$time_taken </TD></TR>";
        print "<TR><TD><CENTER><B>Client Version     </CENTER></B></TD><TD>
$cs_version </TD></TR>";
        print "<TR><TD><CENTER><B>Client Host        </CENTER></B></TD><TD>
$cs_host </TD></TR>";
        print "<TR><TD><CENTER><B>Client Agent       </CENTER></B></TD><TD>
$cs_User_Agent </TD></TR>";
        print "<TR><TD><CENTER><B>Client Cookie      </CENTER></B></TD><TD>
$cs_Cookie </TD></TR>";
        print "<TR><TD><CENTER><B>Referer            </CENTER></B></TD><TD>
$cs_Referer </TD></TR></TR>\n";
        print "</table>";
exit;   
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to