Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Read log which is being updated continuisly

by bimleshsharma (Beadle)
on Sep 20, 2012 at 09:25 UTC ( #994616=perlquestion: print w/replies, xml ) Need Help??
bimleshsharma has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to read log of server which is being updating continuously. I tried below code but i dont see output.Thanks in advance

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

Replies are listed 'Best First'.
Re: Read log which is being updated continuisly
by Arunbear (Parson) on Sep 20, 2012 at 11:13 UTC
    You may need to adjust the parameters you pass to new(). E.g. with
    perl -MFile::Tail -E '$f = File::Tail->new(q[/var/log/foo/bar.log]); p +rint $l while $l = $f->read'
    I had to wait 9 seconds before output was produced. But with
    perl -MFile::Tail -E '$f = File::Tail->new(name=> q[/var/log/foo/bar.l +og], tail=>10, maxinterval=>0.5); print $l while $l = $f->read'
    The output appears right away.
Re: Read log which is being updated continuisly
by nemesdani (Friar) on Sep 20, 2012 at 09:34 UTC
    You must tie() your filehandle, thus the <> operator won't return an undef.

    I'm too lazy to be proud of being impatient.
      Yes you are right but File::Tail->read has capability to read file. Anyway i tried below but still not success.
      use File::Tail; my $name="/some/file/toread/"; my $ref=tie *FH,"File::Tail",(name=>$name); while (<FH>) { print "$_"; }
      but OP isn't using the <> operator, op is using the read method, straight from the synopsis

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994616]
Approved by Corion
and the monks are chillaxin'...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-10-24 08:05 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (286 votes). Check out past polls.