More on perl like tail



Sorry about being tricky with what was an older thread. But I suspect
that thread died... and no one noticed there was an unaswered question
still there.

Shawn C originally suggested I use File::Tail. There was a short
exchange about why and then I began trying to use File::Tail but
haven't been successful with it. The details are below:

Shawn H Corey <shawnhcorey@xxxxxxxxx> writes:

open(FILE,"<./named-pipe") or die "Can't Open ./named-pipe: $!";
while(<FILE>){
print;
if(eof){
sleep 2;
seek (FILE,0,1);
}
}

It seems at least to survive repeated restarts of system logger.

If I write my script based on this code... what I'd be adding would be
code to get 1 or 2 rgx from the cmdline, then write the hits to
various files.

[...]

In the general case, modules usually take care of special cases that you
may not be aware of. That makes them the preferred method of solving a
problem.

In this case, the above code is a kludge. You can tell this because the
program sleeps, rather than waiting on input. When a program does
something to emulate what it really should be doing, it introduces code
that may not work in all cases.

I'm having trouble with File::Tail... or more likely the way I'm
trying to use it is wrongly setup.

But first about that sleep comment. As I read a little of File::Tail
and its very likely I'm not really understanding what I'm reading but,
it appears to be saying that it `sleeps' at times... the times are
a little more sophisticated... but none the less sleep.

Now the problem.

I've taken the first examples in the perldoc File::Tail output:
(http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm)

use File::Tail;
$file=File::Tail->new("/some/log/file");
while (defined($line=$file->read)) {
print "$line";
}

And tied to make it work for my case (/var/adm/slpipe in the script is a
named-pipe that the system logger reads into):

cat fltr_sl

#!/usr/local/bin/perl

use strict;
use warnings;
use File::Tail;

my ($file,$line);
my $fname_in = "/var/adm/slpipe";

$file=File::Tail->new("$fname_in");
while (defined($line=$file->read)) {
print "$line";
}

When I run it, it doesn't show any errors, and appears to be waiting
on the pipe.

But no data ever comes out. I used the same test sequence as for the
earlier script that didn't use File::Tail (posted earlier in this
thread). The sequence is.

1) start the script `fltr_sl' shown above
2) To make sure if data is flowing thru the pipe start
start (in a different xterm) tail -f slpipe too.
2) kill -HUP the system logger.
3) Ensure some data is flowing thru the named-pipe by
running ssh root@localhost from a user account

I see 7-8 lines output to the tail -f slpipe command, but nothing to
the perl script fltr_sl.

And as I write this message, quite a few more lines are appearing at
the `tail -f slpipe' cmd, but still nothing at my perl filter.

Have I made some serious mistake in my attempted usage of File::Tail?

.



Relevant Pages

  • Re: perl like tail -f
    ... It seems at least to survive repeated restarts of system logger. ... If I write my script based on this code... ... But first about that sleep comment. ... I see 7-8 lines output to the tail -f slpipe command, ...
    (perl.beginners)
  • Re: Sleep command quitting
    ... It cannot be that the `sleep` command is terminating. ... That script was popular when I started working at SCO Support in 1989. ... it doesn't really hold the settings you specify. ... anything else comes along and makes further changes, the holdopen script ...
    (comp.unix.sco.misc)
  • Re: WScript.dll not working
    ... But, when i call a script indirectly in my application's exe's context, then it doesn't repond further. ... the sleep method is coded into the ... could call the sleep api directly from script. ...
    (microsoft.public.scripting.vbscript)
  • my script crashes when I try to rename the file!
    ... OK, thanks, but the script does not seem to rename the files. ... You can set the working directory from within your Perl ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (perl.beginners)
  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (comp.lang.perl.misc)