File: select_demo

package info (click to toggle)
libfile-tail-perl 0.99.3-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 292 kB
  • ctags: 114
  • sloc: perl: 551; makefile: 2
file content (44 lines) | stat: -rwxr-xr-x 1,101 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl -w
BEGIN { unshift @INC,"./blib/lib/";}
use File::Tail 0.91;

#$name="/var/log/syslog" unless $name=shift @ARGV;
$debug=shift @ARGV || 0;
$version=shift @ARGV || 0;
if ($#ARGV<0) {
    @ARGV=qw( /var/log/syslog /var/adm/messages /var/adm/lpr.log );
}
foreach (@ARGV) {
    push(@files,File::Tail->new(name=>"$_",debug=>$debug));
}
my $rin='';
if ($version==0) {
    while (1) {
	$nfound=File::Tail::select(undef,undef,undef,60,@files);
	unless ($nfound) {
	    my @ints;
	    foreach(@files) {
		push(@ints,$_->interval);
	    }
	    print "Nothing new! - ".localtime(time)."(".join(",",@ints).")\n";
	}
	foreach (@files) {
	    print $_->{"input"}." (".localtime(time).") ".$_->read unless $_->predict;
	}
    }
} else {
    while (1) {
	($nfound,$timeleft,@pending)=
	    File::Tail::select(undef,undef,undef,60,@files);
	unless ($nfound) {
	    my @ints;
	    foreach(@files) {
		push(@ints,$_->interval);
	    }
	    print "Nothing new! - ".localtime(time)."(".join(",",@ints).")\n";
	}
	foreach (@pending) {
	    print $_->{"input"}." (".localtime(time).") ".$_->read;
	}
    }
}