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.
1

5 Answers 5

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

Sign up to request clarification or add additional context in comments.

3 Comments

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
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.
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!

1 Comment

+1 for right one among all ::SSH. Perl has so many tools, a lot similar, hard to know which good for what.
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).

Comments

0

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

Comments

0
perl -MCPAN -e 'install Net::SSH::Perl'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.