Grep multiline pattern between two words. find particular block from set of files.

Grep Multi-line pattern between two words. find particular block from set of files.
The below shell script searches the list of java files in the current directory and try to look for the catch blocks that doesn't contain any logger initiated messages.
Ex file :
public class Download extends HttpServlet {

static final String sccsId = "%Z%%M% %I% %W% %G% %U%";

private static final PDLogger msgLogger = Logger.getCDSLoggerByName(Logger.PORTAL_LOGGER);
private static final String className = Download.class.getName();

static PublicKey anonymousPublicKey;
// standard anonymous public Key
static {
try {
KeyPairGenerator keyGen = null;
keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair keyPair = keyGen.generateKeyPair();
anonymousPublicKey = keyPair.getPublic();
} catch (Exception ex) {
msgLogger.exception(Level.DEBUG_MIN, className, "{static}", ex);
}

}
}

In the above file there is logger initiated message so, the script won't report any thing. But in case it won't find any keyword "logger" in catch block it reports the information.

Shell Script to recognize multi-line pattern :
#!/bin/sh
echo "Starting Recursive catch block search on the Dir : `pwd`"
fileCount=1
for i in `find . -name '*.java'`
do
echo "Working with file no:$fileCount and the file is:$i"
let fileCount="fileCount+1"
ttl=`cat $i | wc -l`
n=1
TTL=`cat $i | grep -c catch`
while read line
do

found=`echo $line | grep -i "catch" | sed 's/ //g' | cut -d "(" -f1`
if [ $found ]; then
while [ $n -le $TTL ]
do
begLineno=`grep -n catch $i | sed -n "$n"p | cut -d ":" -f1`
EndLineno=`sed = $i | sed 'N;s/\n/:/' | sed -n $begLineno,${ttl}p | grep -v "catch" | grep "}" | sed -n 1p | cut -d ":" -f1`
Logfound=`sed -n $begLineno,${EndLineno}p $i | grep -i Logger | sed 's/ //g' | cut -d "(" -f1 | sed -n 1p`
if [ $Logfound ]; then
echo "Logger message found In the $begLineno,$EndLineno Range Catch block" >> FoundLog.log
else
echo "No Logger messages(s)found In the $begLineno,$EndLineno Range Catch block in file $i" >> NotFound.log
fi
n=`expr $n + 1`
done
fi
done<$i
done

Hope this helps !

Read more


eWAS installation and Configuration

Since long time I know that there exists a eWAS which is express edition, but never played with it.
Today I got a chance to play with and deploy my project in it.

I got the installers from the below urls

http://bob.greenock.uk.ibm.com/tgl_build/embedded_products/ewas/7.0.0.7/EmbeddedExpress_wintel_ia32.zip
http://bob.greenock.uk.ibm.com/tgl_build/embedded_products/ewas/7.0.0.7/EmbeddedExpress_linux_ia32.zip

Installation :
It's simple zip file which will be extracted to desired location when we pass the path where it has to be
by running the below command

nc184197:/opt/builds/eWAS7 # ./install.sh -installRoot /opt/IBM/EWAS

+---------------------------------------+
+       EWAS Version 7.0 Install        +
+---------------------------------------+

    Validating target directory ...
    Copying files ...
    Setting permissions ...
    Installation complete.

Now the next job is to create a profile :
nc184197:/opt/IBM/EWAS/bin # ./manageprofiles.sh -create -templatePath /opt/IBM/EWAS/profileTemplates/default/ -profileName AppSrv01 -profilePath /opt/IBM/EWAS/AppServer/AppSrv01
INSTCONFSUCCESS: Success: Profile AppSrv01 now exists. Please consult /opt/IBM/EWAS/AppServer/AppSrv01/logs/AboutThisProfile.txt for more information about this profile.
nc184197:/opt/IBM/EWAS/bin #
nc184197:/opt/IBM/EWAS/AppServer/AppSrv01/bin # ./startServer.sh server1
ADMU0116I: Tool information is being logged in file
           /opt/IBM/EWAS/AppServer/AppSrv01/logs/server1/startServer.log
ADMU0128I: Starting tool with the AppSrv01 profile
ADMU3100I: Reading configuration for server: server1
ADMU3200I: Server launched. Waiting for initialization status.
ADMU3000I: Server server1 open for e-business; process id is 16248
I guess rest of the things are simple and same ...


To create secure profile in normal WAS -
[root@nc9118041006 bin]# ./manageprofiles.sh -create -templatePath /opt/IBM/WebSphere/AppServer/profileTemplates/default/ -profileName AppSrv02 -profilePath /opt/IBM/WebSphere/AppServer/profiles/AppSrv02 -enableAdminSecurity -adminUserName krishna -adminPassword krishna

Read more

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree