develooper Front page | perl.beginners | Postings from October 2009

perl like tail -f

Thread Next
From:
Harry Putnam
Date:
October 19, 2009 11:39
Subject:
perl like tail -f
Message ID:
87skdfdy9r.fsf@newsguy.com
With a linux background I'm used to being able to my the system logger
right to a named pipe buy means of a `|' (pipe) symbol in syslog.conf

 *.*                               |/var/log/fifo

But on Opensolaris the system logger is enough different than the
sysklogd daemon on linux that the `|' symbol is ignored in
/etc/syslog.conf

On opensolaris, you can tell syslogger to write direct to the fifo.
But it has a side effect
 Lets say you create the fifo

To get data flowing into your filter or script, syslog needs a restart.

But first we use the easy example of cat.

   cat fifo

   Now restart system logger.

   Now anything that sys logger produces will be displayed from the cat
   command.

   Now restart systemlogger again and cat closes as would a common
   shell script or awk.

However the `tail -f' command will not close... it keeps on reading
through restarts.

I want to get that behavior from a perl script.  I realize I could
have my script read from `tail -f fifo|script.pl' but that introduces another
factor... a buffer filling factor where tail -f's shell buffer has to
fill up between writes.

That introduces a lag... so if you want a truly live syslog read.. you
need some kind of fancy buffer flushing or the like.

I'm not sure what it is about the tail -f command that allows it to
keep reading over restarts of system logger (on Opensolaris)... but
how can I emulate whatever it is.. in perl?


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About