LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Daemon shell or perl script to monitor a log file (https://www.linuxquestions.org/questions/programming-9/daemon-shell-or-perl-script-to-monitor-a-log-file-780372/)

khriz 01-06-2010 04:08 PM

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!!

ngwasuma 01-06-2010 04:27 PM

Can you please provide more details on what you hope to achieve, there might be easier methods when details are available.

khriz 01-06-2010 04:37 PM

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.

ngwasuma 01-06-2010 05:04 PM

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?

khriz 01-07-2010 07:35 AM

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.


All times are GMT -5. The time now is 08:10 AM.