line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Rex::Commands::Tail - Tail a file |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Version <= 1.0: All these functions will not be reported. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
All these functions are not idempotent. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
With this module you can tail a file. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
tail "/var/log/syslog"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package Rex::Commands::Tail; |
27
|
|
|
|
|
|
|
|
28
|
32
|
|
|
32
|
|
3042
|
use v5.12.5; |
|
32
|
|
|
|
|
226
|
|
29
|
32
|
|
|
32
|
|
626
|
use warnings; |
|
32
|
|
|
|
|
116
|
|
|
32
|
|
|
|
|
1679
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
require Rex::Exporter; |
34
|
32
|
|
|
32
|
|
212
|
use Data::Dumper; |
|
32
|
|
|
|
|
93
|
|
|
32
|
|
|
|
|
1778
|
|
35
|
32
|
|
|
32
|
|
239
|
use Rex::Commands::Fs; |
|
32
|
|
|
|
|
86
|
|
|
32
|
|
|
|
|
257
|
|
36
|
32
|
|
|
32
|
|
245
|
use Rex::Commands::File; |
|
32
|
|
|
|
|
107
|
|
|
32
|
|
|
|
|
235
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#use Rex::Helper::Run; |
39
|
32
|
|
|
32
|
|
278
|
use Rex::Commands::Run; |
|
32
|
|
|
|
|
151
|
|
|
32
|
|
|
|
|
302
|
|
40
|
|
|
|
|
|
|
|
41
|
32
|
|
|
32
|
|
242
|
use vars qw(@EXPORT); |
|
32
|
|
|
|
|
83
|
|
|
32
|
|
|
|
|
1438
|
|
42
|
32
|
|
|
32
|
|
236
|
use base qw(Rex::Exporter); |
|
32
|
|
|
|
|
109
|
|
|
32
|
|
|
|
|
7738
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
@EXPORT = qw(tail); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 tail($file) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This function will tail the given file. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
task "syslog", "server01", sub { |
51
|
|
|
|
|
|
|
tail "/var/log/syslog"; |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
If you want to control the output format, you can define a callback function: |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
task "syslog", "server01", sub { |
57
|
|
|
|
|
|
|
tail "/var/log/syslog", sub { |
58
|
|
|
|
|
|
|
my ($data) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $server = Rex->get_current_connection()->{'server'}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
print "$server>> $data\n"; |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub tail { |
71
|
0
|
|
|
0
|
1
|
|
my $file = shift; |
72
|
0
|
|
|
|
|
|
my $callback = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$callback ||= sub { |
75
|
0
|
|
|
0
|
|
|
print $_[0]; |
76
|
0
|
|
0
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
Rex::Logger::debug("Tailing: $file"); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
run "tail -f $file", continuous_read => sub { |
81
|
0
|
|
|
0
|
|
|
$callback->(@_); |
82
|
|
|
|
|
|
|
}, |
83
|
0
|
|
|
|
|
|
; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |