rbm1213 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to setup multiple "drones" using Net::SSH::Perl to send a command that creates the work directory, then Net::SCP to copy the files to the drone. The first connection works as intended. The second (a new SSH to the next drone in the list) apparently times out after a 5-10 minute wait. Using debug mode I see the same messages for success and failure - up to the connection closed message:
Setting up drone tux20. tux-queen: Reading configuration data /home/queen/.ssh/config tux-queen: Reading configuration data /etc/ssh_config tux-queen: Connecting to tux20, port 22. tux-queen: Remote version string: SSH-2.0-OpenSSH_4.3p2 Debian-8ubuntu +1 tux-queen: Remote protocol version 2.0, remote software version OpenSS +H_4.3p2 Debian-8ubuntu1 tux-queen: Net::SSH::Perl Version 1.30, protocol version 2.0. tux-queen: No compat match: OpenSSH_4.3p2 Debian-8ubuntu1. tux-queen: Connection established. tux-queen: Sent key-exchange init (KEXINIT), wait response. tux-queen: Algorithms, c->s: 3des-cbc hmac-sha1 none tux-queen: Algorithms, s->c: 3des-cbc hmac-sha1 none tux-queen: Entering Diffie-Hellman Group 1 key exchange. tux-queen: Sent DH public key, waiting for reply. tux-queen: Received host key, type 'ssh-dss'. tux-queen: Host 'tux20' is known and matches the host key. tux-queen: Computing shared secret key. tux-queen: Verifying server signature. tux-queen: Waiting for NEWKEYS message. tux-queen: Enabling incoming encryption/MAC/compression. tux-queen: Send NEWKEYS, enable outgoing encryption/MAC/compression. tux-queen: Sending request for user-authentication service. tux-queen: Service accepted: ssh-userauth. tux-queen: Trying empty user-authentication request. tux-queen: Authentication methods that can continue: publickey,passwor +d. tux-queen: Next method to try is publickey. tux-queen: Trying pubkey authentication with key file '/home/queen/.ss +h/id_dsa' Connection closed by remote host. at /usr/local/share/perl/5.8.7/Net/S +SH/Perl/AuthMgr.pm line 142
Here is the core of the code:
foreach $machine (@machine_name) { $cmd = "$drone_ssh"; { local $ssh; my %params; $params{"protocol"} = '2,1'; $params{"debug"} = '1'; $ssh = Net::SSH::Perl->new( "$machine", %params ); $ssh->login("$drone_user", %params); ( $stdout, $stderr, $exit ) = $ssh->cmd($cmd); undef $ssh; } if ( $exit == 0 ) { { # copy run files to drone local $scp; $scp = Net::SCP->new( "$machine", "$drone_user" ); foreach $filename (@files) { chomp( $target = $filename ); $scp->put( "$target", "$base_directory\/$work_directory\/" ) || ( $scp->{errstr} && print( $LF, "ERROR: scp $target to $machine: $scp->{errst +r}" ) ); } undef $scp; } }
I have tried this without the local $ssh , local $scp and undef $ssh and undef $scp commands, with the same results. Why can't I make SSH connections to multiple machines using Net::SSH::Perl?

Replies are listed 'Best First'.
Re: Net::SSH::Perl timeout
by sh1tn (Priest) on Dec 06, 2007 at 17:29 UTC
Re: Net::SSH::Perl timeout
by salva (Canon) on Dec 06, 2007 at 22:29 UTC
    as the task your are describing seems doable with just SFTP, I would advice you to use Net::SFTP::Foreign that uses the native ssh binary to connect to the remote machines and so it is more robust than Net::SSH::Perl.
      Actually the Net::SCP works very well. I can create an SCP session then put or get files with no errors or drop outs. The SSH is needed to set up the remote machine prior to sending it files, and to execute distributed code remotely prior to retrieving results.