0

I am new to Stackoverflow. So kindly pardon me if i have not made my homework of searching thoroughly. I have a problem in parsing text from tomcat localhost log and catalina.out file. We all know that we receive SEVERE alerts in either of these files. I want a script or free software which will help me to parse the SEVERE alerts alone and mail to my email.

For Example:

SEVERE: Error listenerStart
6 Jul, 2012 2:04:40 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [**********] startup failed due to previous errors
6 Jul, 2012 2:04:40 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

SEVERE: The web application [**************] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
6 Jul, 2012 2:04:40 PM org.apache.catalina.startup.HostConfig deployWAR

INFO: Deploying web application archive server.war
6 Jul, 2012 2:04:40 PM org.apache.catalina.loader.WebappClassLoader validateJarFile

The script must parse from "SEVERE:...." to the text till next "SEVERE:...." or the end of the file. The script can be in shell or python or ruby.

Spidey
  • 193
  • 1
  • 3
  • 11
  • 1
    If you know that you haven't done your research properly, then there really is no excuse, is there. – J. Steen Jul 11 '12 at 11:07
  • Not a script, but look at those topics: http://serverfault.com/questions/63297/good-free-tomcat-log-analyser http://serverfault.com/questions/96720/open-source-tomcat-log-viewer – Pawel Jul 11 '12 at 11:11

1 Answers1

4

Seriously?

What's wrong with bash script like:

grep ^SEVERE catalina.out | mail foo@bar.com

Snapshot requirement? Try this:

grep ^SEVERE catalina.out > tmpFile
diff tmpFile snapshot | mail foo@bar.com
mv tmpFile snapshot
Maria Zverina
  • 10,863
  • 3
  • 44
  • 61
  • is it possible to work this as cronjob? so that as soon as the SEVERE or ERROR are logged it is mailed immediately... – Spidey Jul 11 '12 at 10:40
  • Thanks for the grep command. Bu this collects all the SEVERE alerts and mails. It will be good if the script checks repeatedly the file, parses only one SEVERE alert at a time and mails it. :) – Spidey Jul 11 '12 at 10:59
  • Roll the logs when you mail? Or use cheap snapshots as above? – Maria Zverina Jul 11 '12 at 11:02
  • I like the snapshot solution to track differences since last log-reporting. =D – J. Steen Jul 11 '12 at 11:17
  • Snapshot is not working for me... it says "Null message body; hope that's ok" :( how rolling the log as mailed would go?? – Spidey Jul 11 '12 at 13:14
  • Okay, I wrote a script for this and added this in the cron to run every minute. – Spidey Aug 02 '12 at 06:27
  • 1
    cd [location of the catalina] ps -ef | grep tomcat | grep java | grep -v grep if [ $? -ne "0" ]; then rm -f .ref; exit 0 fi export ALARM="$(cat catalina.out | wc -l)" if [ ! -f .ref ]; then echo $ALARM > .ref elif [ $ALARM -gt $(cat .ref) ]; then sed -n $(cat .ref),$(echo $ALARM)p Catalina.out | egrep -A 70 'SEVERE|ERROR' | egrep -v 'INFO|org.apache' > .reflog; elif [ $ALARM -eq $(cat .ref) ]; then exit 2 fi export SIZE=$(ls -l .reflog | cut -d ' ' -f 5) if [ $SIZE -gt "0" ]; then cat .reflog | mail -s subject mail@goes.here fi echo $ALARM > .ref – Spidey Aug 02 '12 at 06:43