- 论坛徽章:
- 0
|
本帖最后由 sky_peter 于 2010-11-12 16:34 编辑
#!/usr/bin/perl -w
use strict;
use Event::File::tail;
my %event;
our $watch;
sub read_file
{
my ($me, $line)=@_;
if($line=~/^\s*$/)
{
print "truncate\n";
}
else
{
sleep 2;
my $pos=$watch->pos;
print "$line\n";
# print "$watch->id\n";
}
}
sub log_check
{
(my $file)=@_;
$watch=Event::File->tail( file => "$file", cb => \&read_file, timeout => '5' );
Event::loop;
}s
ub start_task
{
my ($arg)=@_;
my $pid=fork;
return 0 if $pid;
log_check($arg);
}
for my $filename (keys %{$event{log}})
{
start_task("$filename");
sleep 10;
}
主要是实现用多进程同时监控多个文件
代码没贴完,for循环中的$filename 代表一个文件名
当代码执行到 my $pos=$watch->pos;时会提示Event: trapped error in `Helper watcher for Event::File->tail ID:1': Can't locate object method "pos" via package "Event::File::tail" at monitor.pl line 44的错误.
百思不得其解. |
|