I have written below script and it reads the file and when ever there is any 400* or 500* word it will give me error message, and now I want to add two more functionality to my script.
I added the script in cronjob to run after 5mins , but now I want the script to continuously run and monitor the log file as it is updating and send me error as per my below requirement.
Rather than checking each line in the file fore 400*, 500* , I want the script to check ""GET / HTTP/1.1" 200" in each line and whenever it is not in the line, it should give me an error message.
find /home/ -type f -name "apache_logs.log" |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">> result.txt fi done