Shell script for continuously monitoring log file

Hi
I have written below log monitoring script to egrep multiple words and redirect the output to a text file and its working fine but I want to add some more below given functionality to it, which is very advance and im not very good in it, so please help if you can :slight_smile:

  1. I am egrepping all the error codes, so I want rather than egrepping all error codes, I should grep for HTTP/1.1 200 which is successful code and which ever line does not have this redirects output to output file.
  2. ignore any line which has /akamai/sureroute
  3. right now I am using cron to run this script every 5 min, so my script will send the same error again and again, so I want the script not to send the same error more than 3 times. (based on the time stamp).
  4. for e.g. if server goes down I do not want 1000's error messages, so if there are more than 100 error messages, script should send only 1 mail.

=====================================

find /home/bharat/ -type f -name "apache_logs.txt" |while read file
  do
    RESULT=$(egrep "[^0](400|401|403|404|405|406|407|408|409|410|411|412|413|414|415|416|417|418|422|425|426|428|429|431|451|500|501|502|503|504|505|511)" $file)
      if [[ ! -z $RESULT ]]
         then
            echo "Error(s) in $file on $HOSTNAME at "$(date)": $RESULT">> email_result.txt
     fi
  done

I think best for you to attempt to modify your script with your new requirements and try to code yourself first, before asking others to do your work for you.

This is always better than posting some a script and then asking others to change it for you to meet your new requirements.

Thanks.

1 Like