|
NAMEFile::Tail::Multi - Perl extension to a stateful tail of multiple files for Unix systems SYNOPSISuse File::Tail::Multi; my @_LIST_OF_FILE_PATHS = ("/path/to/one/file", "/path/to/another/file"); my $rptTail = File::Tail::Multi->new( Function => \&_read_line, LastRun_File => "/path/to/app.lastrun", Files => @_LIST_OF_FILE_PATHS ); sub _read_line { my $lines_ref = shift; foreach ( @{$lines_ref} ) { chomp; next if $_ =~ //; #go play, here's the line } } DESCRIPTIONDerived from MultiTail, this perl library makes it easy to tail a dynamic list of files and match/except lines using full regular expressions and even maintains their state locally. File::Tail::Multi; will tail multiple files and return the records read to a Data Structure. The Data Structure can be processed by File::Tail::Multi functions The files specified are processed in accordance with the following rules: Note: File devices and inode number uniquely identify each entry in the UNIX filesystem. If the stat() command shows them to be the same, then only one will be used. Windows NT filesystem NTFS does not allow links so I don't check for links on NT. (1) Files that exist at program start time will be positioned to Object attribute "NumLines" before input. (2) Files that become available subsequently will be read from the beginning. Attribute ScanForFiles must be set to True (>=1) for the option. (3) If a file that has been selected as per rules 1 or 2 is deleted or truncated input will continue until end-of-file is reached before the file is closed. (4) If a file is deleted and it is recreated it is treated as a new file, will be read from the beginning (5) To conserve file descriptors, files that are selected for input are not actually opened until data is present beyond the input point selected. For example, if a file exists when ptail starts, ptail will determine the file mtime at that time and only open the file when the mtime increases. Note: mtime = Time when data was last modified. Changed by the following functions: creat, mknod, pipe, utime, and write. (6) If an opened file has not been updated for File::Tail::Multi Object attribute "MaxAge" minutes it will be closed. It will be reopened if it is later updated. (7) Since File::Tail::Multi is OO you can alway change its attributes. If you change the list of file to be tailed (Files attribute) the attribute ScanForFiles will set to true and all dir and files ilists will be check for new files. METHODS
EXAMPLE1) use File::Tail::Multi;$tail1=File::Tail::Multi->new ( OutputPrefix => "f", Debug => "$True", Files => ["/var/adm/messages"] ); while(1) { $tail1->read; # $tail1->print; sleep 10; } $tail1=File::Tail::Multi->new : Create new ptail object - Files => Tail file /var/adm/messages - OutputPrefix => Prepend the name of the file beginning of each line in object attribute "LineArray" $tail1->read : Read all line from files $tail1->print : Print all line in object attribute "LineArray"; 2) use File::Tail::Multi; $tail1=File::Tail::Multi->new ( OutputPrefix => "tf", Pattern => "/home/nnysgm/logwatcher/pattern", ExceptPattern => "/home/nnysgm/logwatcher/epattern", Fuction = > \&want, Files => ["/var/adm","/var/log/*.log"] ); while(1) { $tail1->read; # $tail1->print; sleep 10; } sub want { (your code .... ); } $tail1=File::Tail::Multi->new : Create new ptail object - OutputPrefix => Prepend the name of the file and time to the beginning of each line in object attribute "LineArray" - ExceptPattern => Stores in object attribute "LineArray" all lines except those that contain the patterns from file "epattern" - Pattern => Stores in object attribute "LineArray" all lines that contain the patterns from file "pattern" - Fuction => ref to a function that will be run by File::Tail::Multi object. File::Tail::Multi object will pass a ref array to the function of all the lines read from the file and passed through any filters you set in the object. - Files => Tail all files in dir /var/adm and all .log files dir /var/log. $tail1->read : Read all line from files $tail1->print : Print all line in object attribute "LineArray"; 3) use File::Tail::Multi; $tail=File::Tail::Multi->new; $tail->OutputPrefix(tf); $tail->Fuction(\&want); $tail->Files(["/var/adm","/var/log/*.log"]); while(1) { $tail1->read; } sub want { (your code .... ); } AUTHORArvind Tripathy, arvindt@gmail.comSEE ALSO<a href='search.cpan.org/perldoc?File%3A%3ATail'>File::Tail</a><a href='search.cpan.org/perldoc?File%3A%3ATail%3A%3AApp'>File-Tail-App</a> <a href='search.cpan.org/perldoc?MultiTail'>MultiTail</a> Copyright and LicenseCopyright 2008 by Arvind TripathyThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |