use the -f option on tail
from the man pages...
-f Follow. If the input-file is not a pipe, the program
will not terminate after the line of the input-file
has been copied, but will enter an endless loop,
wherein it sleeps for a second and then attempts to
read and copy further records from the input-file.
Thus it may be used to monitor the growth of a file
that is being written by some other process.
This is not perfect as per your specs but it does work.
Also, your while will then be infinite so you might need some condition to exit out of it.
update:
as ikegami points out your --follow=name is something (if not exactly) like the -f option. My system (sun) does not appear to have the same option.
another update:
here's an example of what ikegami is talking about...
use IO::Select;
open (F, 'tail -f somefile.log |') or die;
$select = IO::Select->new(*F) or die "Unable to create select object";
while(<F>) {
$lastrec = "matt: ".$_;
print $lastrec;
while (! $select->can_read(1)) {
print $lastrec;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.