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);
}
}
}
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 :
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
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
Tuesday, March 29, 2011
//
Labels:
Shell Scripting
//
0
comments
//
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
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
Tuesday, March 15, 2011
//
Labels:
Websphere
//
4
comments
//
Popular Posts
-
The best solution to know about these init levels is to understand the " man init " command output on Unix. There are basically 8...
-
How to Unlock BSNL 3G data card to use it with Airtel and Vodafone Model no : LW272 ? How to unlock BSNL 3G data card( Model no : LW272 )us...
-
How to transfer bike registration from one State to other (Karnataka to Andhra)?? Most of us having two wheelers purchased and registered in...
-
ఓం శ్రీ స్వామియే శరణం ఆయ్యప్ప!! Related posts : Trip to Sabarimala - Part 1 Trip to Sabarimala - Part 2 Ayappa Deeksha required things...
-
Following are some of interesting blogs I found till now ...please comment to add your blog here. Blogs in English : http://nitawriter.word...
Popular posts
- Airtel and vodafone GPRS settings for pocket PC phones
- Andhra 2 America
- Ayyappa Deeksha required things
- Blogs I watch !
- Captions for your bike
- DB2 FAQs
- Deepavali Vs The Goddes of sleep
- ETV - Dhee D2 D3
- Evolution of smoking in India Women
- How to make credit card payments?
- init 0, init 1, init 2 ..
- Java-J2EE interview preparation
- mCheck Application jar or jad download
- My SQL FAQs
- My Travelogues
- Old is blod - New is italic
- Online pay methids for credit cards
- Oracle FAQs
- Pilgrimages
- Smoking in Indian Women
- Technology Vs Humans
- Twitter feeds for all Telugu stars on single page.
- Unix best practices
- Unix FAQs