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

Hello,

Using Net::OpenSSH, I'm runing a pipe_out tail -f to search a success/error info in a logfile while a bg command is executing.

When I try to close $stdout redir the script is suspended until I manually kill tail -f command. I tried using the pid returned by pipe_out to kill the command but it's not tail's pid but ssh connection...

Is there anyway to achieve what I'm trying with Net::OpenSSH ?

Thanks

--
fab.

Replies are listed 'Best First'.
Re: Net::OpenSSH and tail -f
by salva (Canon) on Feb 27, 2012 at 12:14 UTC
    OpenSSH support for signaling remote processes is rather limited and so goes for Net::OpenSSH.

    The only way I know to get OpenSSH to kill the remote process when the local one is terminated is requesting a tty:

    my ($in, $out, $pid) = $ssh->open2({tty => 1}, "tail -f /foo/bar"); ... kill TERM => $pid; waitpid $pid, 0; close $in; close $out;
    That may generate a harmless warning from OpenSSH ssh that you can ignore.
      Thanks salva, it works like a charm.
Re: Net::OpenSSH and tail -f
by webmind (Acolyte) on Feb 27, 2012 at 11:31 UTC
    The tail -f will run remotely, so I don't think you'll have access to it's PID. Killing it that way might require another ssh connection.
    If the process runs in shell you might be able to send it a ctrl-c to kill it.