#! /usr/bin/perl -w use File::Remote; # open error file for writing all of the log file(s) # subsequent errors to open(ERROR, ') { chomp $_; # get server and logfile name for opening from file my ($server, $logfile) = split(/|/, $_); # open file ontaining the last file position read by # the script (unique file for each logfile) open(POSITION, "<${server}.${logfile}.line_position") or die $!; my $position; while () { $position = $_; chomp $position; } close(POSITION); # create new File::Remote object, backup remote # logfile and open a file handle to it my $remote_fh = uc "${server}${logfile}"; my $remote = File::Remote->new(); $remote->backup($logfile, "sav"); $remote->open($remote_fh, "<${server}:/log/ ${logfile}") or die $!; # seek to last position in file that was read seek($remote_fh, $position, 0); # traverse particular logfile, write errors to error # file while (<$remote_fh>) { chomp $_; ### SCRIPT STALLS UNPREDICTABLY HERE ### if ($_ =~ /^ERROR/) { print ERROR "$_\n"; } } # get current file position and write it back to # position file my $line_position = tell($remote_fh); open(POSITION, ">${server}.${logfile}.line_position") or die $!; print POSITION "$line_position"; close(POSITION); $remote->close($remote_fh); } close ERROR;