LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-06-2010, 04:08 PM   #1
khriz
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Rep: Reputation: 0
Daemon shell or perl script to monitor a log file


Hi everyone!

I hope you can help me.

I need to create a daemon (shell or perl script) to monitor a log file and read it line by line, in order to find specific words or lines (in this case have to read serial numbers), to be able to compare them with serial numbers in a postgres data base, and show an alert (or something similar) when the serial number in the log file and data base are the same. In other words, must not have repeated numbers in the log file, according with postgres data base.

This script has to be like a daemon, because the log file is being written all day long.

I hope this is clear, and you guys can help me.

Best Regards and Thanks in advance!!
 
Old 01-06-2010, 04:27 PM   #2
ngwasuma
Member
 
Registered: Jan 2005
Distribution: Fedora11
Posts: 45

Rep: Reputation: 16
Can you please provide more details on what you hope to achieve, there might be easier methods when details are available.
 
Old 01-06-2010, 04:37 PM   #3
khriz
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Yes, sure.

Well, What I need is something like: tail -f logfile.log, and detect the line: serial: A2CXXXX and evaluate if there is this serial number in the data base. Obviously need to connect to the database y make a query, in order to know if the serial number is in the database or not.

But this script needs to be running without interruptions, because the log is being filled with more data and serial numbers.

If you need more information, please do not hesitate to ask me.
 
Old 01-06-2010, 05:04 PM   #4
ngwasuma
Member
 
Registered: Jan 2005
Distribution: Fedora11
Posts: 45

Rep: Reputation: 16
If I were you:
1. I would use a bash script to tail the log |grep for the word "serial" and use awk to get the serial number.
2. Use "wget" to run a php script which will check into the DB for matching serial.
<< Not sure what your program does after matching serial entry>>

a. Is it a network program?
b. what kind of alert do you like? - sms? email? or console?
 
Old 01-07-2010, 07:35 AM   #5
khriz
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
It sounds good.

a. Yes, it is a network program.
b. I'd like either a console alert or email alert,

About your second suggestion, how can I do that (wget to run a php script)?

And after the program finds matches of the serial, it be able to show the alert.

And how can I do this script runs like a daemon, or any suggestion to perform this?

Thanks in advance.
 
  


Reply

Tags
programming, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to Continuously scan a log file for success novice82 Linux - Newbie 4 10-09-2009 02:20 AM
Shell Script or perl help. to write sections of a log to a tmp file for mailing pobman Programming 2 02-02-2009 03:30 PM
shell script to monitor log file calipryss Linux - Newbie 14 08-05-2008 10:46 PM
Filtering a CSV file from web log with shell script? Micro420 Programming 8 08-22-2007 03:13 AM
Shell File Upload Monitor Script noodle123 Programming 0 04-22-2002 11:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration