Hi below is my current scripting which will monitor for any errors in the application
logfile="/tmp/application.log"
output=$(grep "ERROR" $logfile)
if [ -n "$output" ]
then
echo "found- send email"
else
echo "not found"
fi
Now I wanted the script not to send the email for one of the occurence which is a known issue
Could you please help me as how can I set this up
The error string I wanted to exclude from monitoring is below
" ERROR - Error while reading from socket
java.net.SocketException: Connection reset "
You don't need to measure grep's output to determine if it's found a string, it outputs an error code that you can use to plug into if directly.
If you want to test for one thing and exclude another though, I'd use awk. Much better than piling on pipe after pipe.
logfile="/tmp/application.log"
if awk '/ERROR/ && !/Error while reading from socket/ { exit 0 } END { exit 1}' $logfile
then
echo "found- send email"
else
echo "not found"
fi
'exit 0' will cause the 'true' section of the if statement to occur. The instant it finds a matching line, it will return 0.
'exit 1' will cause the 'false' section of the if statement to occur. If awk finds no matching lines, it will end up returning 1 (once it runs the END section).
It is the code that awk returns to the shell. Every program returns a code, 0 for success, anything else(1-255) for errors.
Hi Thanks again, I tested the script however its not working as expected
There was an ERROR string apart from the "Error while reading from socket" and the script was not able to catch that error and send email
Sorry incase if you have got my question wrong- basically I wanted to EXCLUDE (not to send the email which is in my original post incase if you have missed) "Error while reading from socket" from the monitoring
had the issue of the 'return value' of the 'exit' in the past - Solaris' awk-s.
logfile="/tmp/application.log"
if awk '/ERROR/ && !/Error while reading from socket/ { _e=1;exit } END { exit _e}' $logfile; then
echo "found- send email"
else
echo "not found"
fi