I am trying to write a script which continiously monitor one specific error message from a log file. This script should continiously monitor the file for the error and send out the email when detect the error message. I tried the below command but fails. Please help me.
tail -f /var/log/messages | grep "file not found" | mail -s "error found" arumon@testing.com
As this new monitor.log file will have all time entries and the cron job will execute every 5 sec, I think this will send the old error messages again and again.
Also i need to avoid the same erros to be send frequently if it is happening continiously.
#!/bin/bash
## justdoit ##
while :; do
lstlf="$(grep "$2" /var/log/messages|sed -n '$p')"
sleep $1;lstll="$(grep "$2" /var/log/messages|sed -n '$p')"
if [[ "$lstlf" != "$lstll" ]] ; then
echo "There is a event about on '$2'"|mail -s "Changes detected!!.." arumon@testing.com ; fi;done