0

Can someone shed me some light, point me in the right direction?

I want to create a script in bash that will checks exceptions in the logs during the startup of Tomcat app. This script should be able to detect the creation of new files on the fly maybe via inotify.

This script should be constantly checking the logs directory for new lines in log files and write the one that contain the words Exception: or ERROR to /var/log/errorcheckernotifier.txt.

When the script detects this line INFO: Server startup in it should write TOMCAT IS STARTED in /var/log/errorcheckernotifier.txt and the number of exceptions detected during the startup.

This script should not overwrite whats in the errorcheckernotifier.txt. Append it instead.

How can I possibly keep this script running and detect further startup, count exceptions, etc.

ninjascorner
  • 121
  • 1
  • 4

1 Answers1

1

I can give you the "start" part of my tomcat init scripts, if that helps.

    start)
        echo -n "Starting $FOO_BASE_JM "
        ## Start daemon with startproc(8). If this fails
        ## the return value is set appropriately by startproc.

        if ps -efwwwwwwwwwwwwww | grep java | grep -q "$FOO_BASE_JM"; then
                echo "Process $FOO_BASE_JM already exists"
                rc_failed 1
        else

        LOGLINES=$(cat /opt/$FOO_BASE_JM/logs/catalina.out | wc -l)

        export CATALINA_OPTS
        ########/sbin/startproc $FOO_BIN
        if [ "$(id -un)" = "tomcat" ]; then
         $FOO_BIN start || rc_failed 1
        else
         /bin/su tomcat $FOO_BIN start || rc_failed 1
        fi

        echo -n "Waiting for process to appear."
        wt=0
        process_seen=true
        while ! ps -efwwwwwwwwwwwwww | grep java | grep -q "$FOO_BASE_JM"; do
                sleep 2
                echo -n .
                wt=$(($wt+1))
                if [ "$wt" -gt 30 ]; then
                        echo
                        echo "Timeout: can't see the process. You should check the logs."
                        rc_failed 1
                        process_seen=false
                        break
                fi
        done
        if [ "x$process_seen" = "xtrue" ]; then
         echo
         echo -n "Waiting for startup."
         wt=0
         while ! tail +$LOGLINES /opt/$FOO_BASE_JM/logs/catalina.out | grep -q "INFO: Server startup"; do
                sleep 2
                echo -n .
                wt=$(($wt+1))
                if [ "$wt" -gt 30 ]; then
                        echo
                        echo "Timeout: can't find signs for successful server startup in log. Please check."
                        rc_failed 1
                        break
                fi
         done
         tail +$LOGLINES /opt/$FOO_BASE_JM/logs/catalina.out | grep -q "INFO: Server startup" && tail +$LOGLINES /opt/$FO
O_BASE_JM/logs/catalina.out | grep "INFO: Server startup"
        fi

        fi # if no process exists

        # Remember status and be verbose
        rc_status -v
        ;;

As an alternative, I can propose using a monitoring tool like Nagios, pointing one of its log monitoring plugins at the catalina.out file (or wherever you are logging to) and search for new error strings or whatever interests you. On our Oracle DBs that works perfectly.

Marki
  • 2,854
  • 3
  • 28
  • 45