Solved

Best Method For Monitoring A Active Logfile

Posted on 2004-04-19
3
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

756 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