Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Checking multiple files..

by nobull (Friar)
on Mar 28, 2005 at 12:35 UTC ( [id://442782]=note: print w/replies, xml ) Need Help??


in reply to Checking multiple files..

I want to check on multiple growing files but I really don't know how to do it.

Basically just use the polling approach you've already partially figured out for a single file but loop over an array (or hash) of filehandles.

However you've not considered the possibility that there may be an incomplete line at the end of the file. To see how to cope with that take a look at how File::Tail does it.

This is really quite complex. Perhaps you should just use File::Tail.

Asside: I think you are saying exit where you meant last.

I know "select()" is somehow related with my question but I cannot figure how to do it... :(

The builtin select() applies when you want to monitor multiple pipe/sockets/devices. These things can be in a state where they have no data to return now but are not at an EOF contition. A file cannot. However File::Tail defines another select().

Oh, and please get into using strictures and warnings now rather than waiting to suffer/inflict the pain that not using them will cause sooner or later.

Replies are listed 'Best First'.
Re^2: Checking multiple files..
by penantes (Acolyte) on Mar 28, 2005 at 13:42 UTC
    Hi there, thanks for your answer.
    I do have a complete version of my question that I setuped using the File::Tail examples, but I was trying to avoid it because for that I need to compile an executable with PAR wich makes a huge bin file (I dont have permission to setup the File::Tail module on the destination server)... oh well!..
    Wont the incomplete line be caugth on the next cycle? Need to do a bit to bit count?!
    So if I need to get stuck with the code bellow how can I do and "uniq" ou the fectched regex values on "$_->read;"

    Best Regards,
    NMA

    #!/usr/bin/perl use warnings; use strict; use File::Tail; my $ConfFile="watchtelecom.conf"; my @LogFiles; my @Files; my $nfound; my $timeleft; my @pending; my $timeout; my $ErrorPatern="error"; #testing purpuses. #my $ErrorPatern="Input: Error reading in input stream"; my $test; my $x; open(CONFFILE, "$ConfFile") or die("Could not open $ConfFile."); foreach (<CONFFILE>) { push(@LogFiles,$_); } close(CONFFILE) or die("Could not close $ConfFile."); foreach (@LogFiles) { push(@Files,File::Tail->new(name=>"$_", maxinterval=>1800)); } while (1) { ($nfound,$timeleft,@pending)= File::Tail::select(undef,undef,undef,$timeout,@Files); foreach (@pending) { my $telcoline=$_->read; if ($telcoline =~ /$ErrorPatern/) { #print $_->{"input"}." (".localtime(time).") ".$_->read; if ($_->{"input"} =~ /TMN/) { print "Via Vodafone: $telcoline"; $test=$telcoline; } else { print "Via TMN: $telcoline"; $test=$telcoline; } } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://442782]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found