Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Problems with Net::OpenSSH

by aeaton1843 (Acolyte)
on Nov 23, 2010 at 17:17 UTC ( [id://873261]=note: print w/replies, xml ) Need Help??


in reply to Re: Problems with Net::OpenSSH
in thread Problems with Net::OpenSSH

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 "$. $_" }

Replies are listed 'Best First'.
Re^3: Problems with Net::OpenSSH
by salva (Canon) on Nov 23, 2010 at 17:46 UTC
    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://873261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found