5

I am fairly new to scripting with perl. I am trying to ssh into a server and perform some commands. I have to provide a username and password.

When trying to run the script that i have so far (code listed below). I get the following error.

I am assuming this means that i need to install/make Net/SSH/Perl.pm, however, when i follow the instructions and tutorials i have found online, none have worked.

Can someone please assist me. I have tried CPAN and ppm, CPAN says it cannot find net::ssh::perl or other variations of that string. And ppm will not even run, i do not see it in my perl directory. Any help is greatly appreciated!


// The code
#!/usr/bin/perl
use Net::SSH::Perl;

$uName = "username";
$pWord = "password";

$unitIp = $ARGV[0];

my $ssh = Net::SSH::Perl->new($unitIp, 35903);
$ssh->login($uName, $pWord);
my $out = $ssh->cmd("java -version");
print $out;

// the error that is returned
Can't locate Net/SSH/Perl.pm in @INC (@INC contains: /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/perl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at needsAName.pl line 31.
BEGIN failed--compilation aborted at needsAName.pl line 31.
prolink007
  • 33,872
  • 24
  • 117
  • 185
  • 3
    From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [What's the easiest way to install a missing Perl module?](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) – daxim May 09 '11 at 20:38

5 Answers5

7

You can try this:

curl -L http://cpanmin.us | perl - --sudo App::cpanminus
cpanm Net::SSH::Perl

case sensitive.

Explanation: 1st line will install "cpanm" - what is IMHO the easiest way installing modules
2nd line will install the module Net::SSH::Perl

clt60
  • 62,119
  • 17
  • 107
  • 194
  • The installation keeps hanging at random "fetching" spots. I did "ctrl+c" during these times when they were taking extreme amounts of time. The installation would continue and finally finished. I tried doing "cpanm Net::SSH::Perl" and it said "-bash: cpanm: command not found". Thanks – prolink007 May 09 '11 at 17:00
  • I figured that was the case, but why is it hanging on some of the fetching? It would sit on one fetching for 10+ minutes. – prolink007 May 09 '11 at 17:28
  • Try check: http://www.cpan.org/modules/INSTALL.html and/or http://search.cpan.org/~miyagawa/App-cpanminus-1.4004/lib/App/cpanminus.pm – clt60 May 09 '11 at 18:56
2

Instead of Net::SSH::Perl try using Net::SSH2 or if you are in an Unix/Linux environment Net::OpenSSH. They are far easier to install!

salva
  • 9,943
  • 4
  • 29
  • 57
1

Why should you use Net::OpenSSH instead of other perl ssh? This is what I found after install it via cpanm:

Net::OpenSSH Vs Net::SSH::.* modules

   Why should you use Net::OpenSSH instead of any of the other Perl SSH
   clients available?

   Well, this is the perldoc writters (biased) opinion:

   Net::SSH::Perl is not well maintained nowadays (update: a new
   maintainer has stepped in so this situation could change!!!), requires
   a bunch of modules (some of them very difficult to install) to be
   acceptably efficient and has an API that is limited in some ways.

   Net::SSH2 is much better than Net::SSH::Perl, but not completely stable
   yet. It can be very difficult to install on some specific operative
   systems and its API is also limited, in the same way as Net::SSH::Perl.

   Using Net::SSH::Expect, in general, is a bad idea. Handling interaction
   with a shell via Expect in a generic way just can not be reliably done.

   Net::SSH is just a wrapper around any SSH binary commands available on
   the machine. It can be very slow as they establish a new SSH connection
   for every operation performed.

   In comparison, Net::OpenSSH is a pure perl module that doesn't have any
   mandatory dependencies (obviously, besides requiring OpenSSH binaries).
Andrew_1510
  • 12,258
  • 9
  • 51
  • 52
0

just type cpan on terminal and then type: force install Net::SSH::Perl

0
perl -MCPAN -e 'install Net::SSH::Perl'
Paul Shiryaev
  • 161
  • 1
  • 9