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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#
# This file is part of StorageDisplay
#
# This software is copyright (c) 2014-2023 by Vincent Danjean.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
use 5.14.0;
# Implementation note: unused module for now
package StorageDisplay::Collect::CMD::Remote;
# ABSTRACT: Collect data on remote machine with SSH
our $VERSION = '2.06'; # VERSION
use StorageDisplay::Collect;
use Net::OpenSSH;
use Term::ReadKey;
END {
ReadMode('normal');
}
use Moose;
use MooseX::NonMoose;
extends 'StorageDisplay::Collect::CMD';
has 'ssh' => (
is => 'ro',
isa => 'Net::OpenSSH',
required => 1,
);
sub open_cmd_pipe {
my $self = shift;
my $ssh = $self->ssh;
my @cmd = @_;
print STDERR "[SSH]Running: ", join(' ', @cmd), "\n";
my ($dh, $pid) = $ssh->pipe_out(@cmd) or
die "pipe_out method failed: " . $ssh->error." for '".join("' '", @cmd)."'\n";
return $dh;
}
sub open_cmd_pipe_root {
my $self = shift;
my @cmd = (qw(sudo -S -p), 'sudo password:'."\n", '--', @_);
ReadMode('noecho');
my $dh = $self->open_cmd_pipe(@cmd);
my $c = ord($dh->getc);
$dh->ungetc($c);
ReadMode('normal');
return $dh;
}
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
my $remote = shift;
my $ssh = Net::OpenSSH->new($remote);
$ssh->error and
die "Couldn't establish SSH connection: ". $ssh->error;
return $class->$orig(
'ssh' => $ssh,
);
};
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
StorageDisplay::Collect::CMD::Remote - Collect data on remote machine with SSH
=head1 VERSION
version 2.06
Commands to collect data for StorageDisplay are run through SSH
=head1 AUTHOR
Vincent Danjean <Vincent.Danjean@ens-lyon.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014-2023 by Vincent Danjean.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|