Sending one input stream to many commands in Linux

Hello guys!

I was seeking a way to process Apache’s access_log file by several parsers simultaneously.

Usually I do it in a straight way:

$ webalizer access_log &
$ awstats access_log &

When access_log is small, this is OK. But if access_log is large, like 15Gb, it is better to read it only once.

We can split one stream into many streams and pass them to many programs using “tee” command and “named pipes”:

$ mkfifo /tmp/fifo.1 /tmp/fifo.2
$ cat access_log | tee /tmp/fifo.1 > /tmp/fifo.2 &
$ (webalizer /tmp/fifo.1; rm -f  /tmp/fifo.1) &
$ (awstats /tmp/fifo.2; rm -f  /tmp/fifo.2) &

Thats all!

 

Leave a Reply