Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
There's more than one way to do things
 
PerlMonks  

Re^2: Net::SSH::Perl, Net::SSH::Expect crashes script if host is unreachable

by Anonymous Monk
on May 08, 2012 at 13:57 UTC ( #969467=note: print w/ replies, xml ) Need Help??


in reply to Re: Net::SSH::Perl, Net::SSH::Expect crashes script if host is unreachable
in thread Net::SSH::Perl, Net::SSH::Expect crashes script if host is unreachable

i specified timeout => 20 in the constructor, and problem was solved.As mine was slow network i took 20seconds as timeout.


Comment on Re^2: Net::SSH::Perl, Net::SSH::Expect crashes script if host is unreachable
Re^3: Net::SSH::Perl, Net::SSH::Expect crashes script if host is unreachable
by mlebel (Friar) on May 24, 2012 at 15:07 UTC

    I ended up trying the long timeout thing and it did work but it would allow the value(in seconds) of the timeout to pass in between commands.

    For example: timeout = 5

    It will take 5 seconds to login, then it will take 5 seconds for the first command to be issued, then another 5 seconds for the next command, so on so forth. and finally 5 seconds for the close command.

    So, in the end, the process ends up spending way too much time per device and therefore this was a show stopper for me.

    The solution for me (since Salva's solution didn't work for me in this thread Net::OpenSSH multiple commands ) was to remove the username/password login and make it use public-key authentication. So far (knock on wood) I haven't had this problem again and the delay in between the commands is gone. This seems to finally round off this solution for me. Here is a sample of code I used to make this work. (taken from it's documentation)

    # Starting ssh without password # 1) run the constructor my $ssh = Net::SSH::Expect->new ( host => "myserver.com", user => 'bnegrao', raw_pty => 1 ); # 2) now start the ssh process $ssh->run_ssh() or die "SSH process couldn't start: $!"; # 3) you should be logged on now. Test if remote prompt is received: ($ssh->read_all(2) =~ />\s*\z/) or die "where's the remote prompt?" $ssh->exec("whoami"); $ssh->exec("/sbin/ifconfig"); $ssh->exec("ls /"); ssh->close();

    I know this post is old but I hope this helps someone anyway.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2013-05-19 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (397 votes), past polls