while(-s $file ) {
open(TF,$file) || last ;
seek(TF,$curpos,0);
@lines=;
$cursorposition = tell(TF);
last if ((stat(_))[7] < $cursorposition);
foreach $nline (@lines){
$newline = substr $nline, 24;
# write out to tailfile $newline
}
close(TF);
sleep 1;
}
}
else
{ sleep 5; }
}
Thanks
Use [mod://File::ReadBackwards]. It's very efficient.
Update:
my $file_name = 'file.log';
my $n = 5;
my $fh = File::ReadBackwards->new($file_name)
or die("Can't read input file: $!\n");
my @lines;
for (1..$n) {
my $line = $fh->readline();
last if not defined $line;
unshift(@lines, $line);
}
print foreach @lines;
@lines=Why not simply read line by line and don't store them?;
tail -f logfile > tailfileI would like to tail it for 10 minutes, restart the tail process for another 10 mintues, copying off tailfile to tailfile.chunk before writing to tailfile again. COuld I use this to do it ? I will check tail archives too.
I would like to tail it for 10 minutes, restart the tail process for another 10 mintues, copying off tailfile to tailfile.chunk before writing to tailfile againPlease be more specific. Are you intending to skip (lose) 10 minutes of logfile? Do you just want to split the logfile into chunks at 10 minute intervals?
What is the fundamental problem you're trying to solve?
-QM
--
Quantum Mechanics: The dreams stuff is made of
--
Oh Lord, wont you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, wont you burn me a Knoppix CD ?
(Missquoting Janis Joplin)
I tried using a cygwin tail, but it locks the file so the original process can't write to it.
LOL -- that's the best joke I've seen about MS Windows in a while. I suppose it could just be taken as a (yet another?) case of midguided implementation on the part of cygwin, but based on the whole brain-damaged approach to file locking foisted by MS, cygwin should not take all the blame (or should at least admit only to justifiable failure).
perlmonks.org content © perlmonks.org and Anonymous Monk, graff, ikegami, LanceDeeply, marto, perlAffen, QM, rinceWind, Skeeve
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03