in reply to Need help to implement Net::SSH::Any

As Corion says, you need to install a backend module.

If you want to run your script on Windows use Net::SSH2, otherwise, if you want to run the script on a Linux/UNIX machine, use Net::OpenSSH (you can also just use Net::OpenSSH without Net::SSH::Any there!).

  • Comment on Re: Need help to implement Net::SSH::Any

Replies are listed 'Best First'.
Re^2: Need help to implement Net::SSH::Any
by mr.sagarbhamare (Novice) on May 03, 2016 at 09:03 UTC
    Thanks Salva and Carion for your reply. Basically, I would like to create this script on our production server does Net::OpenSSH module needs to be purchase ? or is it ok to use on production environment.
      It is Free Software, you can install and run it wherever you want.
        Great, that was my type mistake. New stucked at new error. It seems module not working with if target OS is not Unix / Linux. As in my case i am trying to run my command of one of the tape library.
        ./check_lib.pl 10 172.23.246.78 I am connected to 172.23.246.78 Option not supported capture method failed: child exited with code 1 at ./check_lib.pl line + 27. root@dc2cny - NON-PROD [/home/sbhamare/work/check_tape_library]> cat c +heck_lib.pl #!/usr/local/bin/perl #Check tape library status # use strict; use warnings; use Net::SSH::Any; use v5.10; my %library = ( 9 => "172.23.246.7", 10 => "172.23.246.78", 11 => "172.23.246.79", ); foreach my $lib ( sort keys %library ) { print "$lib $library{$lib}\n"; my $hostname = "$library{$lib}"; my $username = "admin"; my $password = "XXXXXXXX"; my $cmd = "show library status"; if ( my $ssh = Net::SSH::Any->new($hostname, user => $username +, password => $password)) { print "I am connected to $hostname \n"; my @out = $ssh->capture($cmd); $ssh->error and die "capture method failed: " +. $ssh->error; say "Below is the output: \n"; say "@out"; } else { print "I am not able to connect $library{$lib}"; } } ./check_lib.pl 10 172.23.246.78 I am connected to 172.23.246.78 Option not supported capture method failed: child exited with code 1 at ./check_lib.pl line + 27. > perl -d check_lib.pl Loading DB routines from perl5db.pl version 1.32 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(check_lib.pl:10): my %library = ( main::(check_lib.pl:11): 9 => "XX.XX.XX.XX", main::(check_lib.pl:12): 10 => "YY.YY.YY.YY", main::(check_lib.pl:13): 11 => "ZZ.ZZ.ZZ.ZZ", main::(check_lib.pl:14): ); DB<1> s main::(check_lib.pl:16): foreach my $lib ( sort keys %library ) + { DB<1> s main::(check_lib.pl:18): print "$lib $library{$lib} +\n"; DB<1> s 10 172.23.246.78 main::(check_lib.pl:19): my $hostname = "$library{$lib} +"; DB<1> s main::(check_lib.pl:20): my $username = "admin"; DB<1> s main::(check_lib.pl:21): my $password = "XXXXXXXX"; DB<1> s main::(check_lib.pl:22): my $cmd = "show library status +"; DB<1> main::(check_lib.pl:24): if ( my $ssh = Net::SSH::Any-> +new($hostname, user => $username, password => $password)) DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:21): 21: my $class = shift; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:22): 22: my %opts = (@_ & 1 ? (host => @_) : @_); DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:24): 24: my $target = delete $opts{host}; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:25): 25: defined $target or croak "mandatory parameter host missing +"; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:27): 27: my ($user, $passwd, $ipv6, $host, $port) = 28: $target =~ m{^ 29: \s* # space 30: (?: 31: ([^\@:]+) # username 32: (?::(.*))? # : password 33: \@ # @ 34: )? 35: (?: # host 36: ( # IPv6... 37: \[$IPv6_re\] # [IPv6] 38: | # or 39: $IPv6_re # IPv6 40: ) 41: | # or 42: ([^\[\]\@:]+) # hostname / ipv4 43: ) 44: (?::([^\@:]+))? # port 45: \s* # space 46: $}ix or croak "bad host/target '$target' +specification"; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:48): 48: ($host) = $ipv6 =~ /^\[?(.*)\]?$/ if defined $ipv6; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:50): 50: $user = delete $opts{user} unless defined $user; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:51): 51: $port = delete $opts{port} unless defined $port; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:52): 52: $passwd = delete $opts{passwd} unless defined $passwd; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:53): 53: $passwd = delete $opts{password} unless defined $passwd; DB<1> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:54): 54: my ($key_path, $passphrase); DB<1> print $passwd XXXXXXXX DB<2> Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:55): 55: unless (defined $passwd) { DB<2> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:59): 59: my $timeout = delete $opts{timeout}; DB<2> s Net::SSH::Any::new(/usr/local/perl510/lib/site_perl/5.10.1/Net/SSH/Any +.pm:60): 60: my $target_os = _first_defined delete $opts{target_os}, 'u +nix'; DB<2> s Net::SSH::Any::Util::_first_defined(/usr/local/perl510/lib/site_perl/5 +.10.1/Net/SSH/Any/Util.pm:59): 59: sub _first_defined { defined && return $_ for @_; return } DB<2> print $target_os DB<3> s Net::SSH::Any::Util::_first_defined(/usr/local/perl510/lib/site_perl/5 +.10.1/Net/SSH/Any/Util.pm:59): 59: sub _first_defined { defined && return $_ for @_; return } DB<3>
        Awsome it worked for Linux server to fetch uptime command output. Now my next part is to connect to quantum scalar i6000 and i2000 libra +ry and run command "show library status" I have below parameters. 1. Username 2. IP address 3. ssh access 4. password See below sequence of output what i have tried but its failing again d +uring execution. ################################################ cat check_lib.pl #!/usr/local/bin/perl #Check tape library status # use strict; use warnings; use Net::SSH::Any; use v5.10; my %library = ( 9 => "XX.XX.XX.XX", # for security reasons changed 10 => "YY.YY.YY.YY", # for security reasons changed 11 => "ZZ.ZZ.ZZ.ZZ", # for security reasons changed ); foreach my $lib ( sort keys %library ) { print "$lib $library{$lib}\n"; my $hostname = "$library{$lib}"; my $username = "root"; my $password = "XXXXXXXX"; # for security reasons changed my $cmd = "show library status"; if ( my $ssh = Net::SSH::Any->new($hostname, user => $username +, password => $password)) { print "I am connected to $hostname \n"; my @out = $ssh->capture($cmd); $ssh->error and die "capture method failed: " +. $ssh->error; say "Below is the output: \n"; say "@out"; } else { print "I am not able to connect $library{$lib}"; } } ################################################ > ./check_lib.pl 10 YY.YY.YY.YY Permission denied (publickey,password). I am connected to YY.YY.YY.YY capture method failed: unable to establish master SSH connection: bad +password or master process exited unexpectedly at ./check_lib.pl line + 27. ################################################ > ssh admin@YY.YY.YY.YY admin@YY.YY.YY.YY's password: Hello admin, welcome to the Command Line Interface for Quantum Scalar +i6000 library: LTO0XX Type 'help' at the prompt for context-sensitive help. />show library status Component Status Description ------------------------ ------- ----------------------------------- +------------------------- System Health Orange Degraded Control Green Operational Connectivity Green Operational Power Green Operational Cooling Green Operational Robotics Green Operational Robotics Green Operational Robot Green Online Active Drives Yellow Warning; Active events: 4 Event: 458 Yellow Data cartridge L60368L6 has issued +a Tape Alert 3 Event: 459 Yellow Data cartridge L60466L6 has issued +a Tape Alert 3 Event: 460 Yellow Drive sled at [1,1,1,4,1,1] has iss +ued a Tape Alert 37 Event: 462 Yellow Data cartridge C05155L3 has issued +a Tape Alert 33 Drive# 1 (P1 D1) Green Online; Drive Empty Media Loads: 1941 - Read Errors: 50 + - Write Errors: 1207 Read: 89266699MB - Written: 2254575 +167MB Drive# 2 (P1 D2) Green Online; Drive Empty Media Loads: 1160 - Read Errors: 83 + - Write Errors: 571 Read: 205251608MB - Written: 736927 +492MB Drive# 3 (P1 D3) Green Online; Drive Mounted Media Loads: 700 - Read Errors: 46 +- Write Errors: 360 Read: 103106456MB - Written: 473463 +422MB Drive# 4 (P1 D4) Yellow Online; Drive Mounted Media Loads: 285 - Read Errors: 5 - + Write Errors: 31 Read: 21165341MB - Written: 6581404 +8MB Drive# 5 (P1 D5) Green Online; Drive Mounted Media Loads: 1453 - Read Errors: 46 + - Write Errors: 159 Read: 5449221MB - Written: 10000760 +1MB Drive# 6 (P1 D6) Green Online; Drive Mounted Media Loads: 839 - Read Errors: 17 +- Write Errors: 56 Read: 3844530MB - Written: 74439198 +MB Drive# 7 (P1 D7) Green Online; Drive Empty Media Loads: 657 - Read Errors: 10 +- Write Errors: 59 Read: 4948358MB - Written: 42267420 +MB Drive# 8 (P1 D8) Green Online; Drive Empty Media Loads: 526 - Read Errors: 11 +- Write Errors: 113 Read: 11475257MB - Written: 4465934 +4MB Drive# 9 (P1 D9) Green Online; Drive Empty Media Loads: 4153 - Read Errors: 30 +40 - Write Errors: 7810 Read: 51868269MB - Written: 2270923 +27MB Drive# 10 (P1 D10) Green Online; Drive Empty Media Loads: 3547 - Read Errors: 84 + - Write Errors: 167 Read: 29919339MB - Written: 1668944 +70MB Drive# 11 (P1 D11) Green Online; Drive Empty Media Loads: 3090 - Read Errors: 11 +6 - Write Errors: 76 Read: 33787260MB - Written: 1317133 +77MB Drive# 12 (P1 D12) Green Online; Drive Empty Media Loads: 812 - Read Errors: 6 - + Write Errors: 14 Read: 6607257MB - Written: 15037428 +MB /> /> />exit Connection to YY.YY.YY.YY closed. $
        Appeneded my next query in my original question can you please help me to resolve that part. Sorry i am new in perl started learning on last friday and also new in PerlMonks website.
Re^2: Need help to implement Net::SSH::Any
by Anonymous Monk on Aug 01, 2018 at 06:18 UTC
    Thanks, I was stuck on installing dependencies for Net::SSH::Any on Unix, this comment just helped me get away from it & use Net::OpenSSH.