tail -f with cgi

2002-07-12 Thread Max Clark

Hi,

I am trying to write a cgi program to tail -f a log file. I have a perl
script that will open and print the log file, however it closes as soon as
it reads whatever is in the file at that particular time. How do I mimic
tail -f functionality?

Thanks,
Max

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




Re: tail -f with cgi

2002-07-12 Thread zentara

On Fri, 12 Jul 2002 08:24:55 -0400, [EMAIL PROTECTED] (Fliptop)
wrote:

Max Clark wrote:

 I am trying to write a cgi program to tail -f a log file. I have a perl
 script that will open and print the log file, however it closes as soon as
 it reads whatever is in the file at that particular time. How do I mimic
 tail -f functionality?


try the qx// operator:

my $tail = qx/tail -f filename.ext/;
print $tail;

#!/usr/bin/perl
$filename='my.log';

open( IN, $filename ) or die Couldn't open $filename: $!;
my $last;
while ( IN ) {
$last = $_;
}
print Last line is:\n$last\n;






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




Re: tail -f with cgi

2002-07-12 Thread Shawn


- Original Message - 
From: Max Clark [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 11, 2002 6:43 PM
Subject: tail -f with cgi


 Hi,

Hello Max,

 
 I am trying to write a cgi program to tail -f a log file. I have a perl
 script that will open and print the log file, however it closes as soon as
 it reads whatever is in the file at that particular time. How do I mimic
 tail -f functionality?

This is a quick snippet of code I threw together to view file info on a win32 platform 
from the command line, that works on *nix as well.  It should be easy enough to 
convert to use from within a program.

use strict;
print \n\n;
my $size;
open(F,$ARGV[0]) or die Can't open $ARGV[0]: $!\n;
while(F) { $size++; }
close(F);
my ($s1,$s2)=((stat($ARGV[0]))[7],'');
for(;;){
  do {
select(undef,undef,undef,0.25);
$s2=(stat($ARGV[0]))[7];
  } until($s1!=$s2);
  $s1=$s2;
  open(F,$ARGV[0]) or die Can't open $ARGV[0]: $!\n;
  my $row;
  while(F) {
$row++;
print $row: $_ if($size  $row);
  }
  $size=$row;
  close(F);
}

Shawn

 
 Thanks,
 Max



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




RE: tail -f with cgi

2002-07-12 Thread Bob Showalter

 -Original Message-
 From: Max Clark [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, July 11, 2002 7:44 PM
 To: '[EMAIL PROTECTED]'
 Subject: tail -f with cgi
 
 
 Hi,
 
 I am trying to write a cgi program to tail -f a log file. I 
 have a perl
 script that will open and print the log file, however it 
 closes as soon as
 it reads whatever is in the file at that particular time. How 
 do I mimic
 tail -f functionality?

CPAN has a File::Tail module.

But a CGI script isn't designed to be long-running like this. The
web server will eventually time out the request and kill your script.

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




RE: tail -f with cgi

2002-07-12 Thread Camilo Gonzalez

Alright, what's a tail -f?

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 11:09 AM
To: 'Max Clark'; '[EMAIL PROTECTED]'
Subject: RE: tail -f with cgi


 -Original Message-
 From: Max Clark [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, July 11, 2002 7:44 PM
 To: '[EMAIL PROTECTED]'
 Subject: tail -f with cgi
 
 
 Hi,
 
 I am trying to write a cgi program to tail -f a log file. I 
 have a perl
 script that will open and print the log file, however it 
 closes as soon as
 it reads whatever is in the file at that particular time. How 
 do I mimic
 tail -f functionality?

CPAN has a File::Tail module.

But a CGI script isn't designed to be long-running like this. The
web server will eventually time out the request and kill your script.

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

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




Re: tail -f with cgi

2002-07-12 Thread Shawn


- Original Message - 
From: Bob Showalter [EMAIL PROTECTED]
To: 'Max Clark' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Friday, July 12, 2002 11:08 AM
Subject: RE: tail -f with cgi


  -Original Message-
  From: Max Clark [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, July 11, 2002 7:44 PM
  To: '[EMAIL PROTECTED]'
  Subject: tail -f with cgi
  
  
  Hi,
  
  I am trying to write a cgi program to tail -f a log file. I 
  have a perl
  script that will open and print the log file, however it 
  closes as soon as
  it reads whatever is in the file at that particular time. How 
  do I mimic
  tail -f functionality?
 
 CPAN has a File::Tail module.
 
 But a CGI script isn't designed to be long-running like this. The
 web server will eventually time out the request and kill your script.

I don't think he was running from the web server, but will the shell time out in the 
same fashion?

Shawn

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


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




RE: tail -f with cgi

2002-07-12 Thread Bob Showalter

 -Original Message-
 From: Shawn [mailto:[EMAIL PROTECTED]]
 Sent: Friday, July 12, 2002 12:29 PM
 To: Bob Showalter; 'Max Clark'; [EMAIL PROTECTED]
 Subject: Re: tail -f with cgi
 
 
 
 - Original Message - 
 From: Bob Showalter [EMAIL PROTECTED]
 To: 'Max Clark' [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Friday, July 12, 2002 11:08 AM
 Subject: RE: tail -f with cgi
 
 
   -Original Message-
   From: Max Clark [mailto:[EMAIL PROTECTED]]
   Sent: Thursday, July 11, 2002 7:44 PM
   To: '[EMAIL PROTECTED]'
   Subject: tail -f with cgi
   
   
   Hi,
   
   I am trying to write a cgi program to tail -f a log file. I 
   have a perl
   script that will open and print the log file, however it 
   closes as soon as
   it reads whatever is in the file at that particular time. How 
   do I mimic
   tail -f functionality?
  
  CPAN has a File::Tail module.
  
  But a CGI script isn't designed to be long-running like this. The
  web server will eventually time out the request and kill 
 your script.
 
 I don't think he was running from the web server, 

I'm just going off the phrase I am trying to write a cgi program to tail
-f a log file.

 but will 
 the shell time out in the same fashion?

No. It continues to tail the file until interrupted (^C or whatever).

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




RE: tail -f with cgi

2002-07-12 Thread Max Clark

I found the file::tail module on cpan... 

#!/usr/bin/perl -w

use File::Tail;

my $log = /usr/local/apache2/logs/access_log;

$file=File::Tail-new
(
name=$log,
interval=2,
maxinterval=10
);

while (defined($line=$file-read)) {
print $line;
}

It does exactly what I need. I can't seem to get this to work correctly
through cgi. Any ideas?

Thanks,
Max

-Original Message-
From: Max Clark [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 11, 2002 4:44 PM
To: '[EMAIL PROTECTED]'
Subject: tail -f with cgi


Hi,

I am trying to write a cgi program to tail -f a log file. I have a perl
script that will open and print the log file, however it closes as soon as
it reads whatever is in the file at that particular time. How do I mimic
tail -f functionality?

Thanks,
Max

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

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