Wednesday, December 9, 2015

Recursive grep to solve a problem

Sometimes recursive grep can be quite useful to solve a problem  . With recursive grep , you can search the string (error / parameter / message) recursively inside an application ear (or directory) which may get you to the root cause of problem . 

 I am giving you an example where I used the method  of recursive grep to solve a problem which might have taken days to solve it . Off course , this was a Development team problem who did not provide the correct code for promotion . And letting them to solve the  problem would have been a nightmare as they will go through the code , analyze it and then come to some conclusion . They would have provided another ear to promote and this cycle would have continued for days .

This was the error in SystemOut.log

org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'slRetrieveAccessor' defined in ServletContext resource [/c
onf/services/SpringIntegrationSessionLinkServiceDef.xml]: Could not resolve placeholder 'SessionLink_defaultUri'

I went through the file SpringIntegrationSessionLinkServiceDef.xml . I found that there was a parameter {$SessionLink_defaultUri} with dollar sign.


I searched for the string SessionLink_defaultUri inside  Application ear file (xyz.ear )  and found that it was inside SpringIntegrationParameters.properties and was commented .

I uncommented it and recycled JVM .And it fixed the issue.


I identified the string from the xml file and then did a recursive grep inside the application ear file to get to the properties file. I read the properties file and found the solution to the problem.



Below can be several ways to do a recursive grep .

On Solaris
Doing a recursive grep from current directory in all the files down.
find . -type f -exec grep -l "string" {} \;
Or
 Doing a recursive grep from current directory in all the xml files down.
 find . -name *.xml -exec grep -l "string" {} \;

If your string has a forward slash / character then you have to add \ (backward slash ) in front
 find . -name *.xml -exec grep -l "\/opt\/app" {} \;

Note that , I have also added \ before a semicolon ; in the end


No comments: