20081021 netsshperl and remote administration of unix hosts - plembo/onemoretech GitHub Wiki

title: Net::SSH::Perl and remote administration of UNIX hosts link: https://onemoretech.wordpress.com/2008/10/21/netsshperl-and-remote-administration-of-unix-hosts/ author: lembobro description: post_id: 441 created: 2008/10/21 20:37:08 created_gmt: 2008/10/21 20:37:08 comment_status: open post_name: netsshperl-and-remote-administration-of-unix-hosts status: publish post_type: post

Net::SSH::Perl and remote administration of UNIX hosts

For those who’ve never tried it, remotely administering Unix hosts, particularly when they’re not configured to use a common user account database via pam (like Kerberos or LDAP), is usually if not always a royal pain. One of the tools that would make things easier is a simple to use perl interface allowed connecting to and shelling out to the local console over ssh. Net::SSH::Perl is a module that purports to do that. In my own experience the main barrier to using it was in getting all its dependencies to compile and test good on various host systems. In particular, the Math::Pari module almost always took literally days to get installed correctly (just take a look at the CPAN Testers stats for this module — 148 passed to 118 failed installs!). The perl-Net-SSH-Perl and its dependencies (including Math::Pari) are available via yum from EPEL. Run "yum deplist perl-Net-SSH-Perl" to get the dependency list if you like knowing such things before you get started. There's also a related Net::SSH::Expect out there that looks interesting. Following is a simple script that uses Net::SSH::Perl module to get a file listing from a remote machine. Host and user name, password are all fictitious.

#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH::Perl;

my $user = "myuser";
my $pass = "hispassword";
my $target = "testhost.example.com";

my $cmd = "ls -lt";

use strict;
use warnings;
use Net::SSH::Perl;

my $ssh = Net::SSH::Perl->new($target);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);

print $stdout, "n";

__END__;

Copyright 2004-2019 Phil Lembo