I am trying to determine what might be a way to remember a location in a Log file if my FIFO process dies or is killed. Currently the code I have does maintain its location within a growing log, but if the process dies or is killed I lose my location. I was wondering if I write my tell() information to a file on each iteration, and then have the code read this information only upon a new startup of the process would it work? But what I am not sure of is how would I fall back into my loop using the seek() information. Or if anyone has a better way of maintaining a growing log. I have seen the File::Tail module, but am having trouble getting it to work. Anyway, here's my FIFO code. Thanks in advance.
# Preset Values my $LogFile="/usr/local/apache2/eventmgr/ncomount/page.log"; my $PipeName="/usr/local/apache2/pipes/.nco_p_data"; my $naptime=5; my $curpos; open(LOGFILE, "<$LogFile") || die "Couldn't open file $Status - $!\n" +; for(;;){ for($curpos=tell(LOGFILE);LOGFILE;$curpos=tell(LOGFILE)){ while($line=<LOGFILE>){ # print $line; if($line =~ /(.*)\|~\|(.*)\|~\|(.*)/){ $PagerID=$1; $Message=$2.$3; } unless( -p $PipeName) { unlink $PipeName; system("mkfifo -m 644 $PipeName") && die "Can' +t mkfifo $PipeName: $!"; } open(FIFO,">$PipeName") || die "Couldn't open +file $PipeName - $!\n"; print FIFO "NEW|TODAY|NOW|\"\"|$PagerID|$Messa +ge\n"; close(FIFO); } sleep(1); } sleep $naptime; seek(LOGFILE, $curpos, 0); # seek to where we had been }
In reply to Remembering Log Location after process dies. by onegative
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |