use strict; use warnings; use Net::SSH::Perl; my $ssh; $SIG{ALRM} = sub { print STDERR "\nALARM\n"; #$ssh->close; # There is no close - what can I use? #$ssh->_disconnect; # Null subroutine DOES NOT WORK $ssh->break_client_loop; # Seems to work $ssh->sock->close; }; my $perlcmd = join('', ); my $cmd = "/bin/perl - -heartbeat "; while(1) { alarm 5; remcount(); undef($ssh); print STDERR "NEXT...\n"; } sub remcount { $ssh = Net::SSH::Perl->new( "MYHOST", protocol=>2 ); $ssh->login("MYLOGIN", "MYPASS") or die "Failed to login: $!\n"; # STDOUT handler... $ssh->register_handler('stdout', sub { my ($channel, $buffer) = @_; print STDERR "OUT BYTES: ", $buffer->bytes, "\n"; }); print STDERR "REMOTE: $cmd\n"; my ($stdout, $stderr, $exit) = $ssh->cmd($cmd, $perlcmd); } __DATA__ use strict; use warnings; $|++; my $c=0; while(1) { print $c++; sleep 1; }