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

I'm trying monitor a log file on a remote machine by using Net::SSH::Perl and executing the tail -f command on the remote machine. I'm not sure how to set that up so that I can do something useful on the local machine each time a line is added to the log file on the remote machine. (I can't install anything on the remote machine.) Here is the line that I'd like to constantly monitor and capture the output each time something changes. $ssh->cmd('tail -f /var/log/2001-log') Thanks

Replies are listed 'Best First'.
Re: Piping children?
by tilly (Archbishop) on Aug 28, 2008 at 22:36 UTC
    The problem is that Net::SSH::Perl waits until the command ends to send you any output. Your choices are either to modify Net::SSH::Perl to do this (from a glance at the code this is not entirely simple because it is not internally line-oriented), or to use another approach.

    Personally I would set ssh keys up so that the remote machine trusted the local one for autologin, then I would:

    my $command = "ssh $machine 'tail -f /var/log/2001-log'"; open(REMOTE, "$command |") or die "Can't run \"$command\": $!"; while (my $line = <REMOTE>) { ... }