use strict; use warnings; use Net::SSH::Perl; my $HOST='MYHOST'; my $ID='MYLOGIN'; my $DEBUG=0; my $PW='MYPW'; my $perlcmd = join('', ); my $cmd = "/bin/perl - -heartbeat "; # Login to host... my $myssh = Net::SSH::Perl->new( $HOST, protocol=>2, debug=>$DEBUG ); $myssh->login($ID, $PW) or die "Failed to login: $!\n"; listchannels($myssh); # Alarm Handler... $SIG{ALRM} = sub { print STDERR "\nALARM\n"; listchannels($myssh); # Break out of currently running channel.. $myssh->break_client_loop; # Seems to work }; # Display output of multiple commands running on multiple SSH2 channels... while(1) { print STDERR "============================\n"; alarm 5; remcount($myssh); # Add new channel print STDERR "NEXT...\n"; } sub listchannels { my $ssh = shift || die "Missing ssh object"; foreach my $x (@{$ssh->{channel_mgr}{channels}}) { print STDERR "CHAN ", $x->{id}, " :$x\n"; } } sub remcount { my $ssh = shift || die "Missing ssh object"; # STDOUT handler (protocol 2 only)... $ssh->register_handler('stdout', sub { my ($channel, $buffer) = @_; print STDERR "CHAN $channel->{id}: ", $buffer->bytes, "\n"; }); print STDERR "REMOTE: $cmd\n"; my ($stdout, $stderr, $exit) = $ssh->cmd($cmd, $perlcmd); } __DATA__ use strict; use warnings; $|++; my $c='a'; while(1) { print $c++; sleep 1; }