Monitor a log file on Linux and send each line to another program

Posted by mlambie on Server Fault See other posts from Server Fault or by mlambie
Published on 2011-03-15T06:27:18Z Indexed on 2011/03/15 8:11 UTC
Read the original article Hit count: 224

Filed under:
|
|
|

I run an apt-cacher-ng server on Ubuntu Linux which writes logs in the following format:

1299745593|O|149406|XXX.XXX.XXX.XXX|uburep/pool/main/t/tiff/libtiff4_3.9.2-2ubuntu0.4_amd64.deb
1299745593|O|10154976|XXX.XXX.XXX.XXX|uburep/pool/main/l/linux-firmware/linux-firmware_1.34.4_all.deb     
1299748529|O|39368|XXX.XXX.XXX.XXX|uburep/pool/main/n/nagios-nrpe/nagios-nrpe-server_2.12-4ubuntu1_amd64.deb 
1300155440|O|680100|XXX.XXX.XXX.XXX|uburep/pool/main/t/tzdata/tzdata_2011c-0ubuntu0.10.04_all.deb

It shows the timestamp, direction (in or out), byte count, IP and filename.

Every time a line is written to it, I'd like to also send that line to another program. I will have this program insert the line into a database so that I can crunch some statistics about how much bandwidth we're saving through operating a caching server.

I do not want to cat the log file every X minutes (via cron) looking for new entries as it'd be somewhat computationally uneconomical. Instead I'd prefer to have a daemon monitor the log, and when a change is detected, each line is sent to my database-insertion script.

Will swatch achieve this, or are there better options?

© Server Fault or respective owner

Related posts about ubuntu

Related posts about logging