I have a log file which are linked with prefix current date and suffix with IP_address.log 2020_04_22.shared_http_server.192.168.XX.XX.log
I want to monitor these logs at an interval of every 5 minutes. I am looking to schedule a script at an interval of every 5 minutes,in order to grep if 404 error got generated in the log files in last 5 minutes and send the lines of the logs which contains 404 error in different file.
I have written a script to get this done and i am using cron to run this script for every 5 min.Whenever the script runs, it reads the whole log file and throws all the lines of the logs which contains 404 error in different file.But, i want those lines of the logs containing 404 error message to be sent in different file which got generated in last 5 minutes.
find /home/pranav -type f -name "2020_04_22.shared_http_server.192.168.XX.XX.log" |while read file
do
RESULT=$(egrep "[^0](404)" $file)
if [[ ! -z $RESULT ]]
then
echo "Error(s) in $file on $HOSTNAME at "$(date)": $RESULT">> log_result.txt
fi
done
This script is able to grep the lines which contains 404 error message but i want those lines of the logs containing 404 error message to be sent in different file which got generated in last 5 minutes.
Could somebody help me on this what i'm i missing here?
Thank you in advance.