widedave has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -w use File::Remote; # open error file for writing all of the log file(s) # subsequent errors to open(ERROR, '<error.txt') or die $!; # open config file containing log file names and server # locations open(SERVER_LOGS, "<server_logs.txt") or die $!; while (<SERVER_LOGS>) { 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>) { $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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: working with remote log files
by George_Sherston (Vicar) on Oct 13, 2001 at 19:28 UTC | |
|
Re: working with remote log files
by cLive ;-) (Prior) on Oct 13, 2001 at 21:07 UTC | |
by data64 (Chaplain) on Oct 13, 2001 at 23:13 UTC | |
by Fletch (Bishop) on Oct 14, 2001 at 04:48 UTC | |
|
Re: working with remote log files
by data64 (Chaplain) on Oct 13, 2001 at 23:24 UTC | |
|
Re: working with remote log files
by blakem (Monsignor) on Oct 14, 2001 at 01:34 UTC |