Solved

Best Method For Monitoring A Active Logfile

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c language help - file paths 7 141
Trouble linking program with -lcrypt 3 142
C language IDE – Compilers installation 14 68
Arduino EDI - Programming language 3 80
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

867 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

21 Experts available now in Live!

Get 1:1 Help Now