Solved

Best Method For Monitoring A Active Logfile

Posted on 2004-04-19
3
197 Views
Last Modified: 2010-04-15
I want to write a daemon that basically monitors various log files and performs various tasks based on regexp matches. Most of the logs in question are written by syslog or other server processess like apache, weblogic, oracle, etc....

Can anyone point me in the right direction on the best method for doing this? My C is very rusty. I currently have this written in Perl but am trying to move away from perl. The piece I need help with is the reading of the file, etc.... not the text processing or anything else.

Thx,
CC
0
Comment
Question by:rhugga
3 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 50 total points
ID: 10860366

Reading the file is a piece of cake.  Here's all you need:

FILE *logfile;
char LineBuffer[300];

logfile = fopen ("LogFileName.log", "r");

fgets (Linebuffer, 300, logfile);


Kent
0
 
LVL 10

Assisted Solution

by:Mercantilum
Mercantilum earned 50 total points
ID: 10861307
Perl is really the language which fits the best to log analysis... regexp, read, write, ...

In C, anyway, besides the reading of the file (see below)
you will have to find the regexp processing.
An easy way is through the regexp lib  - try " man  regex ".

NB: in the example of Kdo the lines '\n' ended are in buffer usually a simple loop like
while (fgets (Linebuffer, 300, logfile))
{
    process line in Linebuffer
}
fclose (logfile)
0
 
LVL 1

Author Comment

by:rhugga
ID: 10870071

omg. Someone hit me over the head with a cinder block. I had a total brain failure when I posted this question, heh. The woes of using upwards of 5 different programming languages in any given week. Now that I actaully read the question I posted I realize it was probably the dumbest question I have ever asked.

I will split the points to you guys since you both had viable input.

Thanks,
CC
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question