Results 1 to 2 of 2
  1. #1
    Join Date
    May 2014
    Posts
    1

    Unanswered: [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. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Replace the "newentries=" line with the following:
    Code:
    while read line 
    do
       grep "$line" prior_errors.log
       if [ $? -eq 1 ]
       then
          echo "$line" >>prior_errors.log
          echo "$line" >>newentries
       fi
    done <current_entries.log
    newentries is a file though rather than a variable, and new errors are only reported once.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •