line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Interface::Exec::SSH; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
15
|
use v5.12.5; |
|
1
|
|
|
|
|
3
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use Rex::Helper::SSH2; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
84
|
|
13
|
1
|
|
|
1
|
|
8
|
use File::Basename 'basename'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
14
|
1
|
|
|
1
|
|
12
|
use Rex::Interface::Shell; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
require Rex::Commands; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Use 'parent' is recommended, but from Perl 5.10.1 its in core |
18
|
1
|
|
|
1
|
|
37
|
use base 'Rex::Interface::Exec::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
435
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
0
|
|
|
0
|
0
|
|
my $that = shift; |
22
|
0
|
|
0
|
|
|
|
my $proto = ref($that) || $that; |
23
|
0
|
|
|
|
|
|
my $self = {@_}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
bless( $self, $proto ); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub exec { |
31
|
0
|
|
|
0
|
0
|
|
my ( $self, $cmd, $path, $option ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
Rex::Logger::debug("Executing: $cmd"); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
Rex::Commands::profiler()->start("exec: $cmd"); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $shell; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ( $option->{_force_sh} ) { |
40
|
0
|
|
|
|
|
|
$shell = Rex::Interface::Shell->create("Sh"); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
|
|
|
|
|
$shell = $self->shell; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$shell->set_locale("C"); |
47
|
0
|
|
|
|
|
|
$shell->path($path); |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ( Rex::Config->get_source_global_profile ) { |
50
|
0
|
|
|
|
|
|
$shell->source_global_profile(1); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if ( Rex::Config->get_source_profile ) { |
54
|
0
|
|
|
|
|
|
$shell->source_profile(1); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ( exists $option->{env} ) { |
58
|
0
|
|
|
|
|
|
$shell->set_environment( $option->{env} ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $exec = $shell->exec( $cmd, $option ); |
62
|
0
|
|
|
|
|
|
Rex::Logger::debug("SSH/executing: $exec"); |
63
|
0
|
|
|
|
|
|
my ( $out, $err ) = $self->_exec( $exec, $option ); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
Rex::Commands::profiler()->end("exec: $cmd"); |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
Rex::Logger::debug($out) if ($out); |
68
|
0
|
0
|
|
|
|
|
if ($err) { |
69
|
0
|
|
|
|
|
|
Rex::Logger::debug("========= ERR ============"); |
70
|
0
|
|
|
|
|
|
Rex::Logger::debug($err); |
71
|
0
|
|
|
|
|
|
Rex::Logger::debug("========= ERR ============"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (wantarray) { return ( $out, $err ); } |
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $out; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _exec { |
80
|
0
|
|
|
0
|
|
|
my ( $self, $exec, $option ) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# my $callback = $option->{continuous_read} || undef; |
83
|
|
|
|
|
|
|
# $option->{continuous_read} ||= $callback; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $ssh = Rex::is_ssh(); |
86
|
0
|
|
|
|
|
|
my ( $out, $err ) = net_ssh2_exec( $ssh, $exec, $self, $option ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return ( $out, $err ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |