in reply to Re: How to tail file on remote host
in thread How to tail file on remote host

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.

Replies are listed 'Best First'.
Re^3: How to tail file on remote host
by Corion (Patriarch) on Sep 30, 2008 at 21:26 UTC

    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

        Your code as given has syntax errors.

        I don't see what purpose the ->clearerr call is supposed to serve, as the documentation says:

        Clear the given handle's error indicator. Returns -1 if the handle is invalid, 0 otherwise.

        So it would reset the error information, but that won't change neither the eof() status nor will it read additional lines if they've been added..

        Again, as I already told you, the simple way is to just copy the remote file to your local machine and then treat the file as if it were a local file.

Re^3: How to tail file on remote host
by chrism01 (Friar) on Oct 01, 2008 at 06:47 UTC