现象:

  打算利用Perl的模块File::Tail::Multi实现对多个文件的实时处理,可惜程序可以启动,但就是不处理文件内容,急煞我也

用法:

 
  
  1. use File::Tail::Multi; 
  2. my @_LIST_OF_FILE_PATHS = ("/path/to/one/file""/path/to/another/file"); 
  3. my $rptTail = File::Tail::Multi->new(  
  4.       Function => \&_read_line, 
  5.       LastRun_File => "/path/to/app.lastrun"
  6.       Files =>    @_LIST_OF_FILE_PATHS 
  7.       ); 
  8. sub _read_line { 
  9.   my $lines_ref = shift;       
  10.       foreach ( @{$lines_ref} ) { 
  11.               chomp; 
  12.               next if $_ =~ //; 
  13.               #go play, here's the line 
  14.       } 

要点:

  Perl模块File::Tail::Multi中的属性LastRun_File指示的是一个文件,此文件记录被tail的文件最后一次的读取状态,上面指的就是“/path/to/app.lastrun”,如果此文件不存在,则Tail操作就不能完成,即使进程启动正常

解决方法:

  因为LastRun_File所指示的文件不会自动生成,故需手动创建:

 
  
  1. touch /path/to/app.lastrun 

  再启动程序,文件开始被Tail处理,搞定!

  

参考资料:

  http://search.cpan.org/~atripps/File-Tail-Multi-0.1/Multi.pm