in reply to How to tail file on remote host

You simply execute the tail program remotely:

my $remote_filename = '/somewhere/over.txt'; my $remote_host = 'rainbow'; my $cmd = "ssh $remote_host tail -f $remote_filename |"; open my $remote_tail, $cmd or die "COuldn't spawn [$cmd]: $!/$?"; while (<$remote_tail>) { print "Remote: $_"; };

Replies are listed 'Best First'.
Re^2: How to tail file on remote host
by Anonymous Monk on Sep 30, 2008 at 21:22 UTC
    Thanks for the quick reply. This works great. How would you suggest modifying this so that I can call this in a procedure to tail the file from the last point the file was tailed. For example: tail_file($remote_server); # Do some tests - @result = tail_file($remote_server); # Now @result has just the changes caused by the test.

      Copy the whole file to your local machine and then use Algorithm::Diff or remember the last line you processed the last time and start from there.

        I thought it might be easier to make the FH package global and the use the fh->clearerr so that the next time i look at the file handle I would get the new data in the file.

        With a pure filehandle this code worked for me, but I was not sure how I could get this working using this method.

        Also since most of the servers are locked down I can't easily add packages such as Algorithm::Diff.

        The code that worked for me using pure FH was something like:
        open (FH,"/tmp/file); while (<FH>) { push @result,"$_"; print "$_\n"; } FH->clearerr; return @result;
        Thanks,

        Wayne

        Thanks, Wayne