Archive of UserLand's first discussion group, started October 5, 1998.

Re: tail -f in a web page

Author:Emmanuel M. Décarie
Posted:11/6/1999; 8:53:38 PM
Topic:A question for Apache gurus
Msg #:12787 (In response to 12785)
Prev/Next:12786 / 12788

Sorry, Brent, I was responding to Aaron Straup Cope.

I posted a script that I though could help you. Its a CGI but I didn't put any comments in it. Sorry for that too. So here's it is again with some explanations.

Just replace "thePathToTheApacheLog" with the path to your Apache Log, save the file as readable and executable by others in your cgi-bin repertory and then go with your browser to www.mydomain.com/cgi-bin/thisScript.cgi.

#!/usr/bin/perl -T

# On the shebang line (the line above) I use the -T check. # This let Perl check that the script will not do anything dangerous. # Using backticks can be very dangerous but not here AFAIK. # I had the following line because of -T check. # For more details, see: http://www.w3.org/Security/Faq/wwwsf5.html $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';

# I'm using here the CGI.pm module # For more details see: http://stein.cshl.org/WWW/software/CGI/ use CGI ':standard';

# If there is an error in the script, it will be logged in the browser window. use CGI::Carp(fatalsToBrowser);

# Ensure that you declare each variable and use safe construction. use strict;

# Each declaration of a variable have to start with "my" the first time it appears # in the script. # To make a system call and get the result in a variable you use backticks. # Perl provide que qx// shortcut that you can use instead of the backticks. # Here, the result is read in the array @s my @s = qx/tail thePathToTheApacheLog/;

# HTML stuff that CGI.pm do for you. print header; print start_html (-title=>'Tail', -bgcolor=> 'white'); print h1("This a the tail of ...");

# We print every line in the array @s using the magic variable $_ (its the default # input or output). foreach (@s) { print "$_
"; }

# Close the HTML file print end_html;






This page was archived on 6/13/2001; 4:53:22 PM.

© Copyright 1998-2001 UserLand Software, Inc.