Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to extract some data from BIND9's query log. I like to pipe the queries to a script first and then parse it, then log it.

How do I do this? Please help.

logging { channel simple_log { file "/var/log/named/log.sh" versions 10 size 10m; <--- is this possible? print-time yes; print-severity yes; print-category yes; }; category default { simple_log; }; category queries { simple_log; }; };

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You need to use a fifo. This is a "special" file that is really a socket; when processes open this special file and read/write to it, other processes that are connected get the results of those read/writes.

For example, BIND9 would be configured to log to a fifo, then your PHP script would open the fifo as well, and just do reads from it. Every time BIND9 did a write, PHP would return a read.

See man mkfifo, but essentially:

mkfifo /var/log/named/log.fifo

Have BIND9 log to that (remove the versions and size parameters, they won't work with a fifo), then the PHP to read and parse it is up to you, but just remember you open and read from it like any normal file. Reads will block until there is something written to it.

As a test, you can do this:

In Terminal 1:

mkfifo /tmp/test_fifo
cat /tmp/test_fifo

The cat will block because there's nothing to read yet. This is simulating PHP reading from the test_fifo.

Now in Terminal 2:

echo foo >/tmp/test_fifo

Observe how Terminal 1 returns your "foo". This is simulating BIND9 writing something in.

When you're done with a fifo, rm it like any other normal file.

share|improve this answer
    
+1 WOW! Functional, creative, and brainy, Mr. Linux! –  user8290 Dec 13 '11 at 14:08
    
Thank you so much. It works like a charm! –  Nizzy Dec 15 '11 at 6:07
    
Can you mark the answer as accepted if it works please? :) –  Caesium Dec 15 '11 at 9:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.