Solved

Best Method For Monitoring A Active Logfile

Posted on 2004-04-19
3
195 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now