Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Problems with Net::OpenSSH

by aeaton1843 (Acolyte)
on Nov 23, 2010 at 17:17 UTC ( #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 "$. $_" }


Comment on Re^2: Problems with Net::OpenSSH
Download Code
Re^3: Problems with Net::OpenSSH
by salva (Monsignor) 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
Node Status?
node history
Node Type: note [id://873261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2014-10-30 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls