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

Hi, I am completely new to perl and need to write a script which will login to a router and execute few commands. Below is my code and I am getting a error as "Can't find @INC Net::SSH::Perl" I have also tried with Net::SSH and getting the same error. I have tried installing it all the ways but failed. Don't even know where I am going wrong. Please help.

#!/usr/bin/perl -w use strict; use lib qw("/path/to/module/"); use Net::SSH::Perl; my $hostname = "hostname"; my $username = "username"; my $password = "password"; my $cmd = shift; my $ssh = Net::SSH::Perl->new("$hostname", debug=>0); $ssh->login("$username","$password"); my ($stdout,$stderr,$exit) = $ssh->cmd("$cmd"); print $stdout;

Replies are listed 'Best First'.
Re: Perl script on networks.
by thomas895 (Deacon) on Aug 18, 2014 at 06:11 UTC

    What is "all the ways" you tried to install it? Post your command lines and their respective output.
    Also consider checking where you installed it to versus what your @INC is.

    Make sure you read the documentation for ALL the modules you use. For convenience, here are links to them: Net::SSH(::Perl) and lib. Consider also use warnings.
    Module example scripts are also very handy. With most modules, you can find them in the distribution.

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."

      1. I opened command promt and executed "cpan install Net::SSH::Perl" and got the following error.

      Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation. All rights reserved. C:\Users\supriyas>sudo cpan Net::SSH 'sudo' is not recognized as an internal or external command, operable program or batch file. C:\Users\supriyas>cpan install Net::SSH::Perl It looks like you don't have a C compiler and make utility installed. + Trying to install dmake and the MinGW gcc compiler using the Perl Package Man +ager. This may take a a few minutes... Downloading ActiveState Package Repository packlist...failed 500 Can't + connect t o ppm4.activestate.com:80 (10061) ppm.bat install failed: Can't find any package that provides MinGW It looks like the installation of dmake and MinGW has failed. You wil +l not be able to run Makefile commands or compile C extension code. Please +check your internet connection and your proxy settings! CPAN: Term::ANSIColor loaded ok (v4.02) CPAN: Storable loaded ok (v2.45) CPAN: LWP::UserAgent loaded ok (v6.05) CPAN: Time::HiRes loaded ok (v1.9726) Fetching with LWP: http://ppm.activestate.com/CPAN/authors/01mailrc.txt.gz LWP failed with code[500] message[Can't connect to ppm.activestate.com +:80 (10061 )] Warning: no success downloading 'C:\Perl\cpan\sources\authors\01mailrc +.txt.gz.tm p8472'. Giving up on it. Fetching with LWP: http://cpan.perl.org/authors/01mailrc.txt.gz LWP failed with code[500] message[Can't connect to cpan.perl.org:80 (1 +0061)] Warning: no success downloading 'C:\Perl\cpan\sources\authors\01mailrc +.txt.gz.tm p8472'. Giving up on it. Warning: no success downloading 'C:\Perl\cpan\sources\authors\01mailrc +.txt.gz.tm p8472'. Giving up on it. No external ftp command available Fetching with LWP: http://ppm.activestate.com/CPAN/authors/01mailrc.txt.gz LWP failed with code[500] message[Can't connect to ppm.activestate.com +:80 (10061 )] Warning: no success downloading 'C:\Perl\cpan\sources\authors\01mailrc +.txt.gz.tm p8472'. Giving up on it. Fetching with LWP: http://cpan.perl.org/authors/01mailrc.txt.gz LWP failed with code[500] message[Can't connect to cpan.perl.org:80 (1 +0061)] Warning: no success downloading 'C:\Perl\cpan\sources\authors\01mailrc +.txt.gz.tm p8472'. Giving up on it. Warning: no success downloading 'C:\Perl\cpan\sources\authors\01mailrc +.txt.gz.tm p8472'. Giving up on it. No external ftp command available CPAN: YAML::XS loaded ok (v0.41) Please check, if the URLs I found in your configuration file (http://ppm.activestate.com/CPAN, http://cpan.perl.org) are valid. The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/' Could not fetch authors/01mailrc.txt.gz

      2.and just gave "Cpan" so that it will enter to the capn promt where i can give "install Net::SSH::Perl" but giving Cpan alone is opening the capn GUI.

      3. Got a Net::SSH::Perl pm file and saved it in perl/lib/Net but didn't work

        Can't connect to ppm4.activestate.com:80

        Your network connection is broken. Maybe you need to go through a proxy server. Consider setting $ENV{HTTP_PROXY} to the appropriate values.

Re: Perl script on networks.
by f77coder (Beadle) on Aug 18, 2014 at 06:09 UTC

    It looks like you haven't installed the module. Try something like sudo cpan Net::SSH. You might want to update your install of ssh first to latest version.