I'm working on a script where I'm given a log file and need to print some of its info to an HTML file. One problem I'm having is that at the top of the HTML file, I need to print the start of the log date, which will be the earliest date found in the log. I believe I need to implement this in my while loop but I'm not sure how it will work. Here's my code:
#! /usr/bin/perl # CSC 310 Project # 4 #opening log and html file open (LOG, '<', 'IN-access.log'); open (HTML, '>>', 'OUT-access.html'); #printing header/title/format of html print HTML "<HTML><TITLE>Visitors Log</TITLE><BODY>\n"; print HTML "The log file start date is: date() <BR>\n"; <----HERE +!!! print HTML "There were 11 unique visitors in the logfile.<BR>\n"; print HTML "There were 2 visits yesterday<BR>\n"; print HTML "<TABLE border=1><TR><TD>IP</TD><TD>LOGFILE</TD></TR>\n"; #reading log file and assigning values while ($lines = <LOG>){ ($remoteIP,$rfc,$userID,$dateTime,$timeZone,$requestType,$fileRequ +ested,$requestProtocol,$statusCode,$sizeOfFile) = split ' ', $lines; print HTML "<TR><TD>$remoteIP</TD><TD>$remoteIP $rfc $userID $date +Time $timeZone $requestType $fileRequested $requestProtocol $statusCo +de $sizeOfFile</TD></TR>\n"; }
Just for reference, here is an example of what is found in the log file
66.249.65.107 - - 08/Oct/2007:04:54:20 -0400 "GET /support.html HTTP/1.1" 200 11179
111.111.111.111 - - 05/Oct/2004:15:17:55 -0400 "GET / HTTP/1.1" 200 10801
111.111.111.111 - - 06/Oct/2007:11:17:55 -0400 "GET /style.css HTTP/1.1" 200 3225
Do I need to convert the date somehow so I can compare them? Or can I tell perl to just check certain parts of the variable? All suggestions are welcome.
In reply to How to calculate earliest date from log file by jaffinito34
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |