bash - how to filter java exception info

Posted by Michael Mao on Stack Overflow See other posts from Stack Overflow or by Michael Mao
Published on 2010-03-24T00:40:05Z Indexed on 2010/03/24 0:43 UTC
Read the original article Hit count: 425

Filed under:
|

Hi all:

We've got a multi-agent Java environment where different agent would most likely produce all sorts of exceptions thrown to stderr.

Here is a sample taken from the huge exception log

**java.security.AccessControlException: access denied (java.io.FilePermission ..\tournament\Driver\HotelRoomAnalyser.class read)**
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.File.length(Unknown Source)
    at emarket.client.EmarketSandbox$SandboxFileLoader.loadClassData(EmarketSandbox.java:218)
    at emarket.client.EmarketSandbox$SandboxFileLoader.loadClass(EmarketSandbox.java:199)
    at java.lang.ClassLoader.loadClass(Unknown Source)
**java.security.AccessControlException: access denied (java.io.FilePermission ..\tournament\Driver\HotelRoomAnalyser.class read)**
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.File.length(Unknown Source)
    at emarket.client.EmarketSandbox$SandboxFileLoader.loadClassData(EmarketSandbox.java:218)
    at emarket.client.EmarketSandbox$SandboxFileLoader.loadClass(EmarketSandbox.java:199)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at MySmarterAgent.hotelRoomBookings(MySmarterAgent.java:108)

fortunately all top-tier exceptions are denoted by no leading spaces, as wrapped by ** above.

My concern is to get all of the top-tier exception name (delimited by colon :), together with the first line below which contains something like

at emarket.client.EmarketSandbox$SandboxFileLoader.loadClassData(EmarketSandbox.java:218)

Basically, something with padded style, starts with "at" and ends with ".java:108"

So this info can be forwarded to the owner of that error-prone agent and let him/her fix it.

My code in ~/.bashrc is incompleted now :

alias startmatch='java -jar "emarket.jar" ../tournament 100';
function geterrors() 
{ 
    startmatch 2>"$1";
    a=0;
    while read line
    do 
        if true;
            then a=$(($a+1));
                echo $a;
        fi;
    done
}

What it does now is to redirect all stderr to a text file specified by the first argument passed in, and after that, parse that text file line by line, if certain conditions returns true, echo only that line.

And I am stuck with what to do inside the loop.

Any suggestion is much appreciates, any hint is welcomed.

© Stack Overflow or respective owner

Related posts about bash

Related posts about shell