[Help] Script to monitor logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Help] Script to monitor logs
# 1  
Old 05-14-2014
[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 error, I send an email with all faults, and I just want to send me new errors found. Can anyone give me a hand? Thank you!

Code:
 errors=$(grep "System Error Pattern Here" /var/log/)
echo "$errors" > /tmp/current-errors.log

if      [ -e "/tmp/prior-errors.log" ]
         then echo "prior-errors.log Exists" > /dev/null
else
        touch /tmp/prior-errors.log | echo "" > /tmp/prior-errors.log
fi

newentries=$(diff --suppress-common-lines -u /tmp/prior-errors.log /tmp/current-errors.log | grep '+[0-9]')

if
                test "$newentries" != "" && test "$errors" = ""
                then echo "No New Errors" > /dev/null
        elif
                test "$newentries" != ""
                then echo "$errors" | mailx -s "WARNING: Error Messages Detected" noc@yourcompanyhere.com
                echo "$errors" > /tmp/prior-errors.log
fi

# 2  
Old 05-14-2014
Are these log files constantly being written too, if they are, why not archive the files after you search through them.
# 3  
Old 05-14-2014
Replace this line:

Code:
 then echo "$errors" | mailx -s "WARNING: Error Messages Detected" noc@yourcompanyhere.com

with this:

Code:
 then echo "$newentries" | mailx -s "WARNING: Error Messages Detected" noc@yourcompanyhere.com

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. 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

3. 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

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. Shell Programming and Scripting

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? tail -f /logfile |... (2 Replies)
Discussion started by: gklntn
2 Replies

8. Shell Programming and Scripting

script for reading logs of a script running on other UNIX server

Hi, I have a script, running on some outside firwall server and it's log of success or failure is maintained in a file. I want to write a script which ftp that server and reads that file and checks the logs and if failure , I will send mail notification. Please let meknow if I am not... (1 Reply)
Discussion started by: vandana.parwani
1 Replies
Login or Register to Ask a Question