in reply to Net::OpenSSH multiple commands
The solution that ended up working for me was to go back to using Net::SSH::Expect and remove the username/password login and make it use public-key authentication. So far (knock on wood) this seems to work..it's no longer slow and it seems to login everytime..I can also run multiple commands and get the results expected.. 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 => "10.0.0.1", user => 'testuser', 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("terminal width 512"); $ssh->exec("terminal length 0"); my @output = $ssh->exec("show ip accounting"); my @output1 = $ssh->exec("show tech support"); my @output2 = $ssh->exec("show ver"); print "Output = @output\n"; print "Output1 = @output1\n"; print "Output2 = @output2\n"; ssh->close();
I hope this helps someone.
Also, if there is a way to do it using the Net::OpenSSH module, a sample code would be appreciated. Otherwise, enjoy this working solution
Marc
|
|---|