Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Problems with Net::OpenSSH

by Anonymous Monk
on Nov 22, 2010 at 22:49 UTC ( #873067=note: print w/ replies, xml ) Need Help??


in reply to Problems with Net::OpenSSH

I see when you're initializing Net::OpenSSH, you are giving it the username and password there. Is it possible that bypasses the password prompt (or makes Net::OpenSSH hide it from you) and just drops you at the command line one you are connected and authenticated?


Comment on Re: Problems with Net::OpenSSH
Re^2: Problems with Net::OpenSSH
by aeaton1843 (Acolyte) on Nov 23, 2010 at 17:17 UTC

    Thank you to all especially Salva and the anonymous monk. After I read the comments here again, I went back and did some work. The following code works perfectly! Does anyone know whether or not Net::OpenSSH is ithread safe?

    #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use Expect; $| = 1; my $username = ''; my $password = ''; my $enable = ''; my $ip = '10.105.0.62'; my $ssh = Net::OpenSSH->new("$username:$password\@$ip", timeout => 30) +; $ssh->error and die "unable to connect to remote host: ". $ssh->error; my ($pty, $pid) = $ssh->open2pty("show ip arp") or die "unable to run remote command show ip arp"; my $expect = Expect->init($pty); $expect->raw_pty(1); #$expect->debug(2); my $debug and $expect->log_stdout(1); while(<$pty>) { print "$. $_" }
      But your router seems to support commands from SSH without dropping you to the shell. You probably don't need to use Expect at all:
      #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; $| = 1; my $username = ''; my $password = ''; my $enable = ''; my $ip = '10.105.0.62'; my $ssh = Net::OpenSSH->new("$username:$password\@$ip", timeout => 30) +; $ssh->error and die "unable to connect to remote host: ". $ssh->error; my $out = $ssh->pipe_out("show ip arp") or die "unable to run remote command show ip arp"; while(<$out>) { print "$. $_" }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://873067]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-09-16 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (158 votes), past polls