Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Is Net::SSH::Perl still supported? Can I install it on Centos 7?

by cbeckley (Curate)
on Mar 08, 2017 at 02:19 UTC ( [id://1183908]=perlquestion: print w/replies, xml ) Need Help??

cbeckley has asked for the wisdom of the Perl Monks concerning the following question:

I'm attempting to automate and centralize some system administration and deployment tasks, and I've hacked together an ssh wrapper module that works for my initial needs, essentially:

$cmd->{output} = qx($cmd_str); if ( defined $cmd->{output} ) { $cmd->{child_ret_code} = $?; chomp $cmd->{output}; } else { ($cmd->{sys_ret_code}, $cmd->{sys_ret_msg}) = ($!, '|'.$!.'|'); }
but I'm assuming this falls under the column heading:

Problems that have been Solved Before

And sure enough I found Net::SSH::Perl. However ...

The most recent node I found in the monastery referencing Net::SSH::Perl is from 2008.

And while the current version of Net::SSH::Perl on CPAN is 2.01 from April of 2016, the most recent rpm I can find is 1.42, which sent me down a rabbit hole of dependencies.

My question then is in two parts, first, is there a better and/or more current module that provides the functionality of Net::SSH::Perl, and if not, is there a cleaner, easier way to get it installed on a Centos 7 instance, which requires an rpm?

Thanks,
cbeckley

Replies are listed 'Best First'.
Re: Is Net::SSH::Perl still supported? Can I install it on Centos 7?
by salva (Canon) on Mar 08, 2017 at 07:53 UTC

      Thank you! Net::OpenSSH is working beautifully!

Re: Is Net::SSH::Perl still supported? Can I install it on Centos 7?
by hippo (Bishop) on Mar 08, 2017 at 09:43 UTC

    If you want a Perl module which acts as an SSH client and is available as an RPM in the main CentOS 7 repos then you have 1 choice: Net::OpenSSH which is in EPEL. This is only a few versions behind the latest on CPAN.

      Thank you! I was able to install Net::OpenSSH with no problem after I installed the epel-release.

Re: Is Net::SSH::Perl still supported? Can I install it on Centos 7?
by cbeckley (Curate) on Mar 08, 2017 at 18:48 UTC

    Thanks to all the monks that helped me with this!

    For the curious this is what it took to get Net::OpenSSH installed on Centos 7:

    # yum install epel-release # yum install perl-Net-OpenSSH

    And now the salient portion of my ssh module looks thusly:

    my $ssh; my $key_path = $ENV{HOME} . '/.ssh/id_rsa'; if ( ops_cmd_status($cmd) ) { $ssh = Net::OpenSSH->new($cmd->{host}, user => $cmd->{user}, key_pa +th => $key_path); if ( $ssh->error ) { $cmd->{status} = 'failure'; ($cmd->{ssh_retcode}, $cmd->{ssh_retmsg}) = (0 + $ssh->error, '' + . $ssh->error); } } if ( ops_cmd_status($cmd) ) { ($cmd->{output}, $cmd->{std_err}) = $ssh->capture2($cmd->{command}) +; if ( $ssh->error ) { $cmd->{status} = 'failure'; ($cmd->{child_retcode}, $cmd->{child_retmsg}) = (0 + $ssh->error +, '' . $ssh->error); } chomp $cmd->{output}; chomp $cmd->{std_err}; }

    Thanks again for everybody's help.

    Thanks,
    cbeckley

Re: Is Net::SSH::Perl still supported? Can I install it on Centos 7?
by mr_mischief (Monsignor) on Mar 08, 2017 at 16:53 UTC

    It's quite possible to use cpan or cpanm to install on CentOS 7. It's also quite possible to build RPMs.

      I had actually found RPMs for several versions of Net::SSH::Perl, the most current of which being 1.42, however, that required a number of dependencies that were also not in the EPEL.

      Also, using cpan directly seemed to create an additional, separate, independent set of dependencies.

      Neither of those issues are insurmountable, but at least for Centos and possibly (presumably ?) RedHat, something to be considered.

      Thanks,
      cbeckley

        Have you considered using something like Perlbrew? That lets you package up the interpreter and all the modules for your project in one directory. One can then make a simple spec file for rpmbuild that packages that directory if needed.

Re: Is Net::SSH::Perl still supported? Can I install it on Centos 7?
by cbeckley (Curate) on Mar 10, 2017 at 03:20 UTC

    I wasn't sure whether to put this post here, or in Meditations. On one hand this is a continuation of the original question, but on the other hand this is an RFC on how to use Net::OpenSSH.

    This is an excerpt from my module that encapsulates my use of Net::OpenSSH:

    sub ops_do_ssh_shell { my ($cmd) = @_; my $ssh; my $key_path = $ENV{HOME} . '/.ssh/id_rsa'; if ( ops_cmd_status($cmd) ) { $ssh = Net::OpenSSH->new($cmd->{host}, user => $cmd->{user}, key +_path => $key_path); if ( $ssh->error ) { $cmd->{status} = 'failure'; ($cmd->{ssh_retcode}, $cmd->{ssh_retmsg}) = (0 + $ssh->error, + '' . $ssh->error); } } if ( ops_cmd_status($cmd) ) { ($cmd->{output}, $cmd->{std_err}) = $ssh->capture2($cmd->{comman +d}); if ( $ssh->error ) { $cmd->{status} = 'failure'; ($cmd->{child_retcode}, $cmd->{child_retmsg}) = (0 + $ssh->er +ror, '' . $ssh->error); } chomp $cmd->{output}; chomp $cmd->{std_err}; } return $cmd; } sub ops_cmd_status { my ($cmd) = @_; defined $cmd->{status} or $cmd->{status} = 'success'; $cmd->{status} eq 'success' ? 1 : 0; }

    And this is how it would be invoked:

    my $cmd = { user => 'oracle', host => 'randomdbserver.randomdomain.com', command => '/randompath/random_oracle_script' }; my $status = ops_do_ssh_shell($cmd);

    Any insight or corrections of oversight would be greatly appreciated.

    Thanks,
    cbeckley

Re: Is Net::SSH::Perl still supported? Can I install it on Centos 7?
by madtoperl (Hermit) on Mar 08, 2017 at 06:54 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1183908]
Approved by stevieb
Front-paged by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-23 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found