| 1 | # | ||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Rex::Interface::Exec::SSH; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | ▶ | use Rex::Helper::SSH2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use File::Basename 'basename'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use Rex::Interface::Shell; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 1 | require Rex::Commands; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | # Use 'parent' is recommended, but from Perl 5.10.1 its in core | ||||||||||||||||||||
| 18 | 1 | ▶ | use base 'Rex::Interface::Exec::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 21 | 0 | my $that = shift; | |||||||||||||||||||
| 22 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 23 | 0 | my $self = {@_}; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | bless( $self, $proto ); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | return $self; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | ▶ | sub exec { | ||||||||||||||||||
|
Subroutine
exec: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 31 | 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 | ▶ | if ( $option->{_force_sh} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | if ( Rex::Config->get_source_global_profile ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | $shell->source_global_profile(1); | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | if ( Rex::Config->get_source_profile ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 0 | $shell->source_profile(1); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | if ( exists $option->{env} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | Rex::Logger::debug($out) if ($out); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | ▶ | if ($err) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | Rex::Logger::debug("========= ERR ============"); | |||||||||||||||||||
| 70 | 0 | Rex::Logger::debug($err); | |||||||||||||||||||
| 71 | 0 | Rex::Logger::debug("========= ERR ============"); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | ▶ | if (wantarray) { return ( $out, $err ); } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | return $out; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | sub _exec { | ||||||||||||||||||
|
Subroutine
_exec: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 80 | 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 | 1; | |||||||||||||||||||