Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   question on File::Tail (http://www.velocityreviews.com/forums/t900196-question-on-file-tail.html)

golden 10-05-2006 03:06 AM

question on File::Tail
 
Hello All,

I have program that tails a file using file::tail and also periodically

logs to a log file.
The name of the file that I tail changes frequently the format of which

is <file_yyyymmdd_pid.log>.
I would like to put a small "heartbeat message" to my log file. In
that file I wish to also include the current file name that is being
tailed.


I found that file::tail has an input method that simply displays the
logfile name. I have a function that determines the appropriate log
file. and use the "name_change" method to deal with that.


My question is can somebody help me determine how to write to my log
file periodically ( if the read is blocking waiting for data on the
file taile object.


Thanks in advance.
Ian


John W. Krahn 10-05-2006 05:36 AM

Re: question on File::Tail
 
golden wrote:
>
> I have program that tails a file using file::tail and also periodically
>
> logs to a log file.
> The name of the file that I tail changes frequently the format of which
>
> is <file_yyyymmdd_pid.log>.
> I would like to put a small "heartbeat message" to my log file. In
> that file I wish to also include the current file name that is being
> tailed.
>
>
> I found that file::tail has an input method that simply displays the
> logfile name. I have a function that determines the appropriate log
> file. and use the "name_change" method to deal with that.
>
>
> My question is can somebody help me determine how to write to my log
> file periodically ( if the read is blocking waiting for data on the
> file taile object.


I was going to suggest using alarm() but File::Tail uses sleep() and those two
functions may not be compatible so you might want to fork() off a child
process that has a timer and either: sends a SIGUSR1 back to the parent which
catches it and writes to the log file or; have the child write to the log file.



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall

Ted Zlatanov 10-05-2006 03:21 PM

Re: question on File::Tail
 
On 5 Oct 2006, someone@example.com wrote:

> I was going to suggest using alarm() but File::Tail uses sleep() and those two
> functions may not be compatible so you might want to fork() off a child
> process that has a timer and either: sends a SIGUSR1 back to the parent which
> catches it and writes to the log file or; have the child write to the log file.


The latter would be safer.

If the parent and the child decided, before forking, on a shared
memory segment, the parent could write the file name to the shared
memory *when it changes* and the child could read it on every timer.

The parent could also open a pipe device and write the file name to it
whenever the name changes, then the child just does

loop:
sleep
if data in pipe, change log file name to the data
write to log file
end

There are other ways to implement this, but for reliability the pipe
is probably the best way and most easily portable to other Unix
systems. I've had problems with shared memory under Perl on older
Unices.

Ted


All times are GMT. The time now is 05:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.