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 ...
- 12-10-2011 #1Just 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:
It would instead do this:Code:[Server] Ding [Server] Dong [Server] Blah
If I sound like a maniac just tell me, but I know nothings* impossible.Code:/usr/bin/accesslog [Server] Ding /usr/bin/accesslog [Server] Dong /usr/bin/accesslog [Server] Blah
Any ideas? Thanks!
* To a proportion, don't quote me.
- 12-10-2011 #2
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, etcYou must always face the curtain with a bow.
- 12-12-2011 #3Linux Guru
- 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!


Reply With Quote