Serach a keyword based on last updated

Hi,

Can you guys help in writing script based upon my requirement.

The requirement is :

Th script should poll or sniff an log file every minute or every second. The log file name is "license.txt"

In the log file if it founds "not valid" then it should send mail to a group.

the logic here is :

1) it should check log file only if it gets updated

2) Every time it should check in the log which is updated latest

3) The search shouldn't start from the beginning of the file.

Let me know if any details you need.

Taking into account the time it takes to send, receive, pop, and read a mail msg, even if someone in that group, twiddling their thumbs, is constantly checking their mails, examining the log file every second is overkill, even per minute is too much. Five minutes might be a good interval. Do your log file lines/entries have time stamps?

Hi Rudic,

Agreed. my intention was to check periodically and it is not yet decided to what are the time intervals the cronjob needs to check.

For now just think that its 5 minutes and yes my log file has timestamps, please find the log :

Mar 5 02:52:20 app21 info message received invalid license for the license number 21345.
Mar 5 02:52:49 app21 messages processed successfully
Mar 5 02:57:48 app21 info message received invalid license for the license number 732900.
Mar 5 02:58:50 app21 messages processed successfully
Mar 5 02:58:50 app21 messages processed successfully

I was thinking about comparing time stamps between last run and actual run, but that might be too coarse a criterion.
Create a little awk script that picks the previous last line no. from a file, skips all lines up to that no., checks the lines to EOF, creating your mail text, and saves the last line from this run in above file for the next run.