Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

from text file to web page

Status
Not open for further replies.

tepok

Vendor
Jun 3, 2003
2
FI
I have a constantly updating text file (a log file), and I'd like to see it on a web page in almost real time. So what I need is a script which echoes the text file to html (perhaps tail, i use linux) and then autorefresh to the page.
I am sure this is a trivial task for you who are experienced but I have not yet managed to get anything useful done, so any help is greatly appreciated.
 
I think this is close....' have not tried to run it.... ;-)

Code:
#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';

my $cgi = new CGI;
my $url = $cgi->url();

print $cgi->header,
      qq(<head>
         <meta HTTP-EQUIV=&quot;REFRESH&quot; 
         CONTENT=&quot;10;  url=$url&quot;>
         </head><body><p>);
         
my @records = `tail -100 /path/to/log/file.txt`;
foreach (@records) { print &quot;$_<br />\n&quot;; }

print qq(</p></body></html>);

There may be a typo or two.... hopefully it'll get you headed in the correct direction. Note that those are not quotes around the 'tail' command, they are backticks (below the ~ on the keyboard). Also, you'll need to modify the path and name of the log file to read. The 'CONTENT: 10' tells the page to refresh every 10 seconds.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thanks, that was exactly what I was looking for. Thank you really much, you saved me a lot of time :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top