On my side, I prefer not to use the System TAIL at all... Instead, i use a
simple open, and I restart the loop each time the end of file is reached...
There is a small example...
#!/usr/bin/perl -w
use strict;
use IO::File;
my $FILENAME = './test.txt';
my $FH = new IO::File;
$FH->open($FILENAME) or die "open Failed\n";
while($FH)
{
while(my $line = <$FH>)
{
print "READ: $line";
# Exit the loops if "last" is found
if($line =~ /last/)
{
close $FH;
$FH = undef;
last;
}
}
sleep 1; # sleep for 1 sec each time the end of file is reached
}
print "\n\n Script Exit \n\n";
I hope this can be usefull to you ;-)
-----Original Message-----
From: Mark Borghardt [mailto:[EMAIL PROTECTED]]
Sent: 22-Jan-2002 13:18
To: '[EMAIL PROTECTED]'
Subject: Tail -f and select - Again
Sorry if this is a rehash (no Perl pun intended) of a subject already
covered, but I have read all of the archived messages and scoured the net
for a solution to my problem with no success.
What I want to do is read data from a growing file (tail -f) until a special
record arrives, at which point I would like to close the file and reopen
another one repeating the process.
I almost got it to work with
$datafile="File1";
while () {
open(DATAIN,"tail +0 -f $datafile |");
while ( <DATAIN> ) {
print $_;
if (substr($_,0,4) eq "SPEC") {
$datafile=substr($_,4);
last;
}
}
close(DATAIN);
}
Datafiles are all 9 characters and a <LF> per record and of the form:
Record 01
Record 02
SPECFile2
The only problem is that I have to hit <Control C> on the keyboard to kill
the old tail process.
Is there a way to send a signal to the open tail process so I don't have to
hit <control c> ?
Is there a better strategy for doing this?
Any help would be appreciated.
Mark Borghardt