----- 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]