Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Best Method For Monitoring A Active Logfile

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
rhugga
Asked:
rhugga
2 Solutions
 
Kent OlsenData Warehouse Architect / DBACommented:

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
 
MercantilumCommented:
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
 
rhuggaAuthor Commented:

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now