I am reading in a logfile, writing the records that are to be pruned from
the top to an archived file.  I then open a temp file store the
modification time of the
logfile and write the remainder of the log to the tempfile.  Then I check
the current modification time of the logfile if it has changed then I close
the tempfile and go repeat from the opening of the tempfile again.  I have
put in a sleep which will hopefully cause the program to awaken after
whatever activity has taken place.

Now it works as is.  But I was trying to modify the code so that I stored
the location in the logfile just before the end of file marker.  Then if
there was a change made I could just write piece(s)  added to the logfile
to the tempfile, which shoud be much faster.

I cannot use any file locking methods to do this, many applications write
to this file and some of the logfiles I will be processing are heavy
activity and they are not equipped to handle the logfile being locked.

Here is what I came up with:

            unless ( open(TEMP_OUT, ">$self->{TEMP_FILE}") )
                {
                        die("$0: Cannot open $self->{TEMP_FILE}: $!\n");
                }

                while ( $log_changed )
                {
                        my $mod_time    = 0;

                        # When the records were being checked, the first
line
                        # of the next record must be read in to see if it
                        # contains a record seperator.  If it does then the
                        # the last complete record is dumped.  If the last
                        # complete record that is dumped was the last
record
                        # to prune the line we just read in would be lost
                        # so we backtrack to the beginning of the first
record
                        # not to be pruned.

                        print "Seeking : $file_location\n";
                        if ( !seek(LOG_IN, $file_location, 0) )
                        {
                                die("$0: could not find location in
logfile\n");
                        }
                        }

                        $mod_time = (stat LOG_IN)[9];

                        while ( $lineIn = <LOG_IN> )
                        {
                                print "$lineIn";
                                print TEMP_OUT $lineIn;
                                $file_location = tell LOG_IN;
                        }

                        if ( $mod_time ne (stat LOG_IN)[9] )
                        {
                                my ( $msg ) = "$0: $self->{LOG} change
while ";
                                $msg.="copying, retrying.\n";
                                print STDERR  "$msg";

                                $log_changed = 1;

                                # Sleep to wait for inactivity
                                sleep 2;
                        }
                        else
                        {
                                $log_changed = 0;
                        }

                }


However it doesn't work.  The temp file never gets any data in it (or does
not appear too) but my print statement within the reading while loop does
correctly print out the lines of data.

Any thoughts ?

-----------------------------------------
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]


Reply via email to