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.
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
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!
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).
just type cpan on terminal and then type: force install Net::SSH::Perl
perl -MCPAN -e 'install Net::SSH::Perl'
Related
I am trying to build LDV project by following this instructions, and i know nothing about perl.
i am getting the following error while running the test
ldv-task: NORMAL: Calling LDV-core.
Can't locate SOAP/Lite.pm in #INC (#INC contains: /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/5.10.0/x86_64-linux /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/5.10.0 /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/site_perl/5.10.0/x86_64-linux /home/acsia/perl5/perlbrew/perls/perl-5.10.0/lib/site_perl/5.10.0 .) at /home/acsia/Desktop/LDV/consol-tools/ldv-core/ldv-core line 7.
BEGIN failed--compilation aborted at /home/acsia/Desktop/LDV/consol-tools/ldv-core/ldv-core line 7.
output of
perlbrew use
is :EDITED:
Currently using perl-5.22.0
output of
locate SOAP/Lite.pm
is
/usr/local/lib/perl5/site_perl/5.22.0/SOAP/Lite.pm
output of
which perl
is
/usr/local/bin/perl
and the LDV-core file is starting like this by default
#!/usr/bin/perl -w
#
my $instrumnet = 'ldv-core';
use FindBin;
# To prevent meaningless module warnings use this instead of use.
BEGIN { $SIG{'__WARN__'} = sub{}; require SOAP::Lite; SOAP::Lite->import(); $SIG{__WARN__}='DEFAULT'; }
use POSIX ":sys_wait_h";
use XML::Twig;
use IO::Socket::INET;
#use File::MimeInfo;
use File::Basename;
use Cwd qw(abs_path);
etc,... etc....
Thanks for your time...
If LDV-Core isn't yours, you should install SOAP::Lite using your system's package manager. If it's yours, read on.
perlbrew plays with your PATH so that executing perl will execute the desired perl.
But your script explicitly uses /usr/bin/perl, so which perl is currently selected using perlbrew switch or perlbrew use is irrelevant.
Stop overriding the default install location, and stop looking where you shouldn't.
unset PERL_MM_OPT
unset PERL_MB_OPT
unset PERL5LIB
unset PERLLIB
echo -ne 'o conf makepl_arg ""\no conf commit\n' | cpan
echo -ne 'o conf mbuildpl_arg ""\no conf commit\n' | cpan
The first four lines only have a temporary effect. You should stop setting those variables in your login script to make the change permanent.
Install SOAP::Lite in the desired Perl.
perlbrew use perl-5.22.0 # Or perl-5.10.0 or whatever
cpan SOAP::Lite
Fix your script's shebang.
perl -i~ -pe'
next if $. != 1;
s/^#!.*//s;
$_ = "#!$^X\n$_";
' LDV-core
PS — You don't need use FindBin;.
perlbrew perl is a way to install many perl versions in same machine. It is like virtenv in python. Perlbrew allow you to switch between various versions of perl and run perl programs against those versions.
system perl means the default version of perl which mostly come with linux distros. perlbrew changes that version against which program needs to run and your program will start running against different version.
If you are making something which does not require a lot of perl versions it is always better to use one version of perl and run programs against them.
Also if you are using linux distros and do not want to get into cpan and how to install perl modules, best is to search for corresponding libraries against that module and install them. For example in your case i search this way
aptitude search soap | grep perl
This give me two libraries on my ubuntu machine of which one is against this module. Installing them is easy and you can focus on your work rather than on how to install cpan modules.
I am trying to use ROUGE on Windows:
So the first few lines of the file:
use XML::DOM;
use DB_File;
use Getopt::Std;
#-------------------------------------------------------------------------------------
use vars qw($opt_a $opt_b $opt_c $opt_d $opt_e $opt_f $opt_h $opt_H $opt_m $opt_n $opt_p $opt_s $opt_t $opt_l $opt_v $opt_w $opt_2 $opt_u $opt_x $opt_U $opt_3 $opt_M $opt_z);
And it gives me this error:
Can't locate DB_File.pm in #INC (#INC contains: C:/Perl64/site/lib C:/Perl64/lib
.) at C:\RELEASE-1.5.5\ROUGE-1.5.5.pl line 174.
BEGIN failed--compilation aborted at C:\RELEASE-1.5.5\ROUGE-1.5.5.pl line 174.
I am new to perl. All i need is ROUGE to work. What does this mean? How can i fix it?
The author of the perl script probably did not test his script
on windows.
You could probably hack the script to make it work, but
since you're new to perl and seem to be in a hurry,
I suggest you use linux/unix for ROGUE.
The README for ROGUE mentions linuxy things like bash etc,
which is a clue.
If you insist, here's a way to get the perl script running
on windows, but be warned, further errors can pop up
as you get deeper in to the features.
remove activeperl
install strawberryperl 32bit
cpan install XML:DOM
cpan install DB_File
try:
close existing windows
open a new command prompt
run this command
ppm install DB_File
close window
try running rogue again
hope it helps
---
if you have a copy of the rogue application please share it so we can check it out.
Im trying to run a perl script which involves ssh to a remote server and while executing this code, it throws an error like
Can't locate Net/SSH/Perl.pm in INC <#INC contains:C:/Perl/site/lib c:\perl\lib at line5.
I open ppm graphical UI and installed NET-SSH, area= site
but still not able to execute this script
Here is the script
use strict;
use warnings;
use Net::SSH::Perl;
my $ip=12.14.142.22;
my $user = "qwerty";
my $pass = "termide";
my $ssh = Net::SSH::Perl->new($ip, use_pty => 1);
$ssh->login($user, $pass);
While Foo::Bar often includes a Foo::Bar::Baz module, that isn't the case here.
Net::SSH and Net::SSH::Perl are different distributions. You need to install Net::SSH::Perl.
You should install Net::SSH::Perl, not Net::SSH. The error message is clean about that :)
Net::SSH2 is another SSH client that works on Windows and far easier to install. A PPM is available from here.
our system admin recently upgraded my OS and perl (to 5.12.3). when I load up the local::lib environment variables, it appears to break anything that depends on xs:
demianshell~> perl -e 'use Storable; store({a=>1}, 'test')'
demianshell~> eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)
demianshell~> perl -e 'use Storable; store({a=>1}, 'test')'
Assertion ((svtype)((_svi)->sv_flags & 0xff)) >= SVt_RV failed: file "Storable.xs", line 3753 at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/_store.al) line 263, at -e line 1
is there an easy fix to this?
If you are saying that your only Perl has been upgraded from something other than Perl 5.12.*, and the binary components of your local::lib installations haven't, then sorry no, there is no easy solution to this apart from rebuilding the local::lib modules to your new Perl. Perl XS components are just not viable across major Perl revisions.
This is why it is often a good idea not to trust any system Perl, as it is outside your control. It's always a good plan to use your own Perl installs so you can control this, either with App::perlbrew or just a separate Perl install somewhere.
I'd like to have all the installed CPAN modules updated automatically every night, so I've placed the following command in the crontab:
#daily cpan -i $(cpanp -o | perl -lane 'print $F[3]')
However, whenever this is run I get the following error message:
Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and
LINES environment variables didn't work. The resize program didn't work. at
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Term/ReadKey.pm
line 362.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/Term/ReadLine
/Perl.pm line 63.
What can I do to get this working?
Come back on Monday. I'll add a -u command to cpan to do that if you promise to test it for me. You'll have to get the latest cpan from App::Cpan.
Okay, don't wait until Monday. I've pushed the change to the cpan-script Github repo, and App-Cpan 1.56_15 is on its way to CPAN.
Let me know if you have any problems or the new feature doesn't do what you want.
Please use brian d foy's answer as he added a cpan option to do this
Are you trying to update the list of modules with CPAN or actually update any out of date modules (d/l, compile, install)? This could be dangerous as modules could change interface and existing scripts would fail. This error is due to CPAN trying to use Term::ReadLine and Term::ReadKey to interrogate the terminal.
If you really want to upgrade all your modules, you can use this command:
perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
This is a small change from the command given in the documentation to interrogate CPAN for all outdated modules:
https://metacpan.org/pod/CPAN#PROGRAMMERS-INTERFACE
The COLUMNS and LINES environment variables didn't work.
Try setting the COLUMNS and LINES environment variables.
COLUMNS=80
LINES=24
#daily cpan -i $(cpanp -o | perl -lane 'print $F[3]')