send email when exceptions occur in catalina.out
-
23-12-2019 - |
Question
i am working on this. monitor tomcat log file called "Catalina.out" for "Exception" error. The script should send us the E-mail as soon as it finds the string "Exception" in the file. Any thoughts?
Can this be done via tomcat/log4j?
Solution
Try this one:
#!/bin/bash
while [ 1 = 1 ]
do
rcode="`tail -n 1000 catalina.out 2>&1 | grep -o Exception`"
if [ "$rcode" = "Exception" ]
then
echo "Something went wrong." \
| mail -s "your subject" mail@mailaddress.com
fi
sleep 180
done
There are certainly some improvements to be done. E.g. the "-n 1000" or sleeping for 180 seconds. But it should do for a start.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow