in reply to Re: Net::OpenSSH how to stop(zap) capturing after time
in thread Net::OpenSSH how to stop(zap) capturing after time

Wow, awesome, but... If i set timeout to 1 and command to `cat /dev/urandom` it takes only 13 seconds ( "$cmd & sleep $timeout; kill \$!" )
And if command is `echo Hello, World` script returns Exit Code 1, but i think i can fix it :)

Replies are listed 'Best First'.
Re^3: Net::OpenSSH how to stop(zap) capturing after time
by salva (Canon) on Mar 22, 2011 at 10:48 UTC
    You could probably write a more reliable wrapper in Perl, and install it on your remote servers, or use a one-liner.

    Another option is to write your own time-limited capture method. Use pipe_out to launch the remote command and read from the returned pipe until the timeout expires. Closing the pipe will deliver a SIGPIPE to the remote process killing it.

      Thanks, it works
      my ($out, $pid) = $ssh->pipe_out("$cmd"); my $sel = new IO::Select($out); my $str = ""; while (1) { @ready = $sel->can_read(1); if(@ready > 0) { if(my $new = <$out>) { $str .= $new; } else { last; } } if ($ConnectionDeadline < time()) { kill 15, $pid; $str .= "\nConnection timeout\n"; last; } }