I was going to write some code to tail a log file and detect when it rolled and then close/reopen it. Then I saw a reference to File::Tail and it sounded like just what I want. So I thought I'd try something very simple. I literally copied the sample usage script, pointed it to a file called /tmp/xxx with a few lines in it and nothing happens! I tried to echo some additional lines to the file they're not reported either. Could there be some versioning thing going on? I'm running perl 5.8.8 and File::Tail 0.99.3.
#!/usr/bin/perl -w
use File::Tail;
$file=File::Tail->new("/tmp/xxx");
while (defined($line=$file->read)) {
print "$line";
}
When I run it there is no output. I even put a print right after the first call to make sure it gets to the while line and it does. Any ideas what I could try to see what's wrong?
I even tried eliminating the while and simply doing the read since I know there's something in the file:
use File::Tail;
$file=File::Tail->new("/tmp/xxx");
print "opened\n";
$line=$file->read;
print "after read\n";
print "$line";
and when I run it, it seems to be hanging on the read. The doc says you can pass it a non-zero value for debug so I tried 99 and got nothing. It feels like the file isn't getting opened but I have no ideas why.
Finally I tried getting even more creative with more instrumentation as well as some error handling.
use File::Tail;
$file=File::Tail->new(name=>"/tmp/xxx", debug=>99, interval=>1, maxint
+erval=>1) or print "ERROR1: $!\n";
print "ERROR2: $!\n";
print "opened\n";
$line=$file->read;
print "after read\n";
print "$line";
It now looks like $! is getting set to "Inappropriate ioctl for device", but only when I report it with ERROR2 and not ERROR1. Is that message even real? In other words the constructor doesn't seem to be failing. I'm real confused by what I'm seeing.
-mark
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.