question on File::Tail

G

golden

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
 
J

John W. Krahn

golden said:
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
 
T

Ted Zlatanov

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top