monitor new logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting monitor new logs
# 1  
Old 08-11-2012
monitor new logs

I would like to monitor logfile for specific keyword and send email once detected. I'm trying out the code here, the script is scheduled to run every minute. Everytime it runs, the same log will be detected and send email. Anyway it can be improved to detect only new logs?


Code:
tail -f /logfile | while read line ; do

if [[ `echo $line | grep "keyword"` ]]
then
    
     a="`echo $line | grep "keyword"`"
         echo $a "detected"
         email alert
    
fi

done


Last edited by methyl; 08-12-2012 at 02:59 AM.. Reason: Please use code tags.
# 2  
Old 08-12-2012
Yes.
The technique is to use:
Code:
grep "keyword" /logfile > selection.txt

Then on the next iteration compare the number of occurances of "keyword" in this file with the previous version of the file.


Ps: There is no unix/Linux commad called email.
# 3  
Old 08-13-2012
In the below example when a new record is inserted into "logile" and it contains the "search_for" string then the code between the if/fi will be executed:
Code:
search_for="blue"
tail -f /logfile | while read line
do
  if [[ $line = @(${search_for}) ]]; then
    echo "detected ${search_for}"
    email alert
  fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Infrastructure Monitoring

Searching for Saas Monitor service which monitor my servers which are sitting in different providers

Sorry if this is the wrong forum Searching for Saas Monitor service which monitor my servers which are sitting in different providers . This monitor tool will take as less CPU as possible , and will send info about the server to main Dashboard. The info I need is CPU / RAM / my servers status (... (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

[Help] Script to monitor logs

Hello friends, as they are? First of all sorry for my poor English. I tell them what is my problem. I have the following script, which is basically what makes error search for a pattern within a folder containing logs. The script works fine, the problem is that whenever I find a pattern of new... (2 Replies)
Discussion started by: romanrsr
2 Replies

4. Shell Programming and Scripting

Monitor logs for exception and if exception come then sent an email

Hi Folks, please advise , I have logs generated on unix machine at location /ops/opt/aaa/bvg.log , now sometimes there come exception in these logs also, so I want to write such a script such that it should continuously monitor these logs and whenever any exception comes that is it try to find... (3 Replies)
Discussion started by: tuntun27272727
3 Replies

5. UNIX for Dummies Questions & Answers

Software to monitor the logs dynamically

Hi Folks, I have to monitor the logs for exceptions and the logs will be dynamic and will keep updating now one way is to use the command on putty that is tail -f but could you please advise any software in which I can dynamically monitor the logs and if an exception come it highlights thos... (4 Replies)
Discussion started by: tuntun27272727
4 Replies

6. Red Hat

Want to Monitor the Pidgin Logs

Hi Team, Am the Root user I want to monitor the user's chat actions. So How do I check the Remote system users Pidgin Chat logs history. And where the logs will be stored exactly?? Give me a solution!! (2 Replies)
Discussion started by: Adhi
2 Replies

7. Hardware

Fedora 16 dual monitor - dual head - automatic monitor shutdown

Hi, I am experiencing troubles with dual monitors in fedora 16. During boot time both monitors are working, but when system starts one monitor automatically shut down. It happend out of the blue. Some time before when I updated system this happend but then I booted older kernel release and... (0 Replies)
Discussion started by: wakatana
0 Replies

8. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies
Login or Register to Ask a Question