sub main_script() { my @servers ('a', 'b'); my %con_opts; $con_opts{timeout} = 120; $con_opts{async} = 1; my $script = "some_script.pl"; my %opts; $opts{stdin_pipe} = 1; $opts{stdout_pipe} = 1; $opts{stderr_to_stdout} = 1; foreach @servers { $con_opts{host} = $_; $ssh{'SSH'} = Net::OpenSSH->new(%con_opts); ($ssh{'STDIN'}, $ssh{'STDOUT'}, undef, $ssh{'PID'}) = $ssh{'SSH'}->open_ex(\%opts, $script) or die "Error ".$ssh{$host}->error; } ## Waitpid loop to clean up terminating OpenSSH sessions } #### sub start_child() { my $pid = fork(); if(!defined $pid or $pid < 0) { # ... Fork error die(...); } if($pid > 0) { # In parent return; } # In child process exec("child script", args); } #### foreach (@child_pids) { kill "SIGTERM", $_; } #### while(waitpid(...)) { # Reap the children } #### debug2: client_process_control: accepted tty 0, subsys 0, cmd /usr/level1/sw/tmcvay/bin/PWL debug2: client_process_control: got fds stdin 6, stdout 7, stderr 8 debug2: fd 6 setting O_NONBLOCK debug2: fd 7 setting O_NONBLOCK debug2: fd 5 setting O_NONBLOCK debug1: channel 0: new [client-session] debug2: channel 0: send open debug2: callback start debug2: client_session2_setup: id 0 debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 debug2: channel 0: request env confirm 0 debug1: Sending command: /path/bin/some_script.pl debug2: channel 0: request exec confirm 0 debug2: callback done debug2: channel 0: open confirm rwindow 0 rmax 32768 debug2: channel 0: rcvd adjust 2097152 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug2: channel 0: rcvd eof debug2: channel 0: output open -> drain debug2: channel 0: obuf empty debug2: channel 0: close_write debug2: channel 0: output drain -> closed debug2: channel 0: rcvd close debug2: channel 0: close_read debug2: channel 0: input open -> closed debug2: channel 0: send close debug2: channel 0: is dead debug2: channel 0: garbage collecting debug1: channel 0: free: client-session, nchannels 1 # open_ex: ['ssh','-O','exit','-T','-S','/home/.../.libnet-openssh-perl/b-3018-562986','--','b'] debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 194.6 seconds debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0 debug1: Exit status -1 # _waitpid(3388) => pid: 3388, rc: # open_ex: ['ssh','-O','exit','-T','-S','/home/.../.libnet-openssh-perl/a-3018-242049','--','a'] debug1: channel 0: free: client-session, nchannels 1 debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 195.0 seconds debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0 debug1: Exit status -1 # _waitpid(3389) => pid: 3389, rc: