question on File::Tail

Discussion in 'Perl Misc' started by golden, Oct 5, 2006.

  1. golden

    golden Guest

    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
     
    golden, Oct 5, 2006
    #1
    1. Advertising

  2. 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
     
    John W. Krahn, Oct 5, 2006
    #2
    1. Advertising

  3. golden

    Ted Zlatanov Guest

    On 5 Oct 2006, 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
     
    Ted Zlatanov, Oct 5, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Count Dracula

    A better way to tail a file

    Count Dracula, Aug 9, 2003, in forum: C++
    Replies:
    1
    Views:
    377
    Johan den Boer
    Aug 10, 2003
  2. Josh Endries
    Replies:
    1
    Views:
    114
    Florian Frank
    Sep 1, 2004
  3. Christopher Aldridge
    Replies:
    0
    Views:
    122
    Christopher Aldridge
    Aug 9, 2005
  4. x1

    Rails/Ajax/File::Tail?

    x1, Oct 13, 2006, in forum: Ruby
    Replies:
    0
    Views:
    99
  5. Terry Michaels

    Tail Call Optimization (Tail Recursion)

    Terry Michaels, Apr 18, 2011, in forum: Ruby
    Replies:
    16
    Views:
    315
    Robert Klemme
    Apr 20, 2011
Loading...

Share This Page