Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, heres a challenge for you... I have a file: /opt/server/access.log And whenever anything goes to write to access.log I want it to send each line to /usr/bin/accesslog X For ...
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    2

    When writing to file, send contents to an application

    Hi, heres a challenge for you...

    I have a file: /opt/server/access.log

    And whenever anything goes to write to access.log I want it to send each line to /usr/bin/accesslog X

    For example, if you where appending this to the file:

    Code:
    [Server] Ding
    [Server] Dong
    [Server] Blah
    It would instead do this:

    Code:
    /usr/bin/accesslog [Server] Ding
    /usr/bin/accesslog [Server] Dong
    /usr/bin/accesslog [Server] Blah
    If I sound like a maniac just tell me, but I know nothings* impossible.

    Any ideas? Thanks!

    * To a proportion, don't quote me.

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    From your post, it is not entirely clear to me, if /opt/server/access.log is written by only one process (server) or arbitrary processes.
    Arbitrary would need another approach than the one explained below.

    What is /usr/bin/accesslog?

    For the sake of argument, I will assume:
    - there is a server process writing to /opt/server/access.log
    - /usr/bin/accesslog is a script/binary written by you, that shall process the serverlog.
    Correct me, if these assumptions are wrong.


    Should they be correct, then only three (or better four) things need to happen:
    1) Use rsyslog. It is a powerful reimplementation of syslog.
    The server should log to a syslog facility instead of directly writing the logfile.
    If the server cannot syslog, then use the rsyslog file input module (imfile)

    2) Configure rsyslog
    a) to write the access.log
    b) additionally write to a named pipe Actions - rsyslog.conf rsyslog

    3) Redesign /usr/bin/accesslog to read from the named pipe.
    Sorry to say, but your approach to startup a new instance of this script/binary for *every single logline* is in the best case a waste of resources and for any real use, it will kill the server machine.

    4) The named pipe needs to exist before rsyslog starts. Also both writer (server) and reader (/usr/bin/accesslog) should exist and be running.
    So some control and monitoring is needed.
    Control: Puppet can be used Documentation | Puppet Labs - Learning ? Resources
    Monitoring: The usual suspects are nagios, xymon, etc
    You must always face the curtain with a bow.

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,975
    If you want to intercept the updates to file A and append that and some more data to file B, then you should be able to use the inotify tools and API's to do that.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...