Change values in Log4j.xml using ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change values in Log4j.xml using ksh script
# 1  
Old 01-06-2011
Change values in Log4j.xml using ksh script

Hi,

I am new to UNIX and shell scripting.
I have to create a shell script(ksh) which parses log4j.xml file for a given webservice name and change the corresponding value from INFO to DEBUG or vice-versa.

My log4j.xml looks like:-

Code:
<!-- Appender WEBSERVICENAME-->
<appender name="WEBSERVICENAME" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="PATH_OF_LOG_FILE" />
<param name="threshold" value="DEBUG" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d|%-5p|[%t]|%X{serviceId}|%X{requestId}|%c{1}:%L|%m%n" />
</layout>
<filter class="CLASSNAME">
<param name="values" value="WEBSERVICENAME"/>
<param name="MDC" value="serviceId"/>
</filter>
</appender>

IN above example i have to change:-

Code:
<param name="threshold" value="DEBUG" />

to
Code:
<param name="threshold" value="INFO" />

Note:- there are many weservices in the xml file for whom
Code:
<param name="threshold" value="DEBUG" />

is present in there appender. So i only want to change the value for input WEBSERVICE NAME only.

I searched some AWK examples but could not come up with one to suit my purpose.

Kindly help.

Last edited by pludi; 01-13-2011 at 06:16 AM..
# 2  
Old 01-06-2011
This will change the value from DEBUF to INFO for webservice "WEBSERVICENAME"
Code:
perl -i -lp0e 's/(?<=name="WEBSERVICENAME")(.*?)DEBUG/$1INFO/s' Log4j.xml

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 01-13-2011
Hi Bartus,

Thank you for your post it is working.
But i have a another query.

Suppose the "WEBSERVICENAME" i am searching is not present in log4j.xml.
Then i have to create an entry as follows:-

Code:
<category name="WEBSERVICENAME">
<priority value="DEBUG"/>
<appender-ref ref="APPENDERNAME"/>
</category>

and this entry has to be inside the block whose start and end is defined by following Heading:-
Code:
<!--=====================================================-->
<!--================== Le root logger ==================-->
<!--=====================================================-->

I know how to append at the end of the line but how to do within a particular block i don;t know.

Moderator's Comments:
Mod Comment Please use code tags for listings.

Last edited by pludi; 01-13-2011 at 06:17 AM..
# 4  
Old 01-17-2011
Hi Bratus,

Your command is working but I get WEBSERVICE name as input and when i use a variable in your command it doesnot work.

I am trying to use

perl -i -lp0e 's/(?<=name="$CLASS_NAME")(.*?)DEBUG/$1INFO/s' log4j.xml

where CLASS_NAME has the input class name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract values from xml file script

Hi, please help on this. I want extract values of xml file structure and print in determined way. <ProjectName> --> only appears once <StructList> --> is the top node <Struct> node --> could be more than 1 NameID, STX, STY, PRX, PRY --> appears only 1 time within each <Struct> node... (10 Replies)
Discussion started by: Ophiuchus
10 Replies

2. UNIX for Beginners Questions & Answers

Script to populate (2) values in .XML

Good Afternoon Team - I"m asking for assistance on a piece of code to populate two values in an XML file. I have it working perfectly using CScript for DOS, but I have a need to do that same process in a Linux environment. Here is the XML I need to modify: <?xml version="1.0"... (5 Replies)
Discussion started by: SIMMS7400
5 Replies

3. UNIX for Beginners Questions & Answers

How to change values in xml file?

I have xml file like below, i want change the values at default-value place of each argument name using shell script. like where argument name= protocol and default-value=tcp, where argument name =port and default-value= 7223, where argument name = username and default-value=test, example ... (12 Replies)
Discussion started by: s1s2s3s4
12 Replies

4. Shell Programming and Scripting

Reading xml tags from ksh script

Hi, I have an XMl file, below is sample: <TRANSFORMATION DESCRIPTION ="Created by:- " NAME ="LKP_FT_T_FILEK" OBJECTVERSION ="1" REUSABLE ="YES" TYPE ="Lookup Procedure" VERSIONNUMBER ="1"> </TRANSFORMATION> I need to read the tag, and if the tag is TRANSORMATION, i want to check the Type... (6 Replies)
Discussion started by: kedar_laveti
6 Replies

5. Shell Programming and Scripting

Change attribute value in xml using shell script

hi, i am new to unix and i have a problem. -------------------------------------------------------------- sebben.xml <envelope> <email> sebben@example.com </email> </envelope> script_mail written in the vi editor. #!/bin/sh script to change the value in attribute <email> echo... (3 Replies)
Discussion started by: sebbenw
3 Replies

6. Shell Programming and Scripting

Change XML file structure script

Hi to all, Maybe someone could help me. I want to transform the structure of a xml file. I have this input.xml: <?xml version="1.0" encoding="utf-8"?> <votings> <file name="Reference 19762"> <case id="No. 3 Div. 870"> <j v="1">Peter</j> <j v="1">Ely</j> <j... (10 Replies)
Discussion started by: cgkmal
10 Replies

7. Shell Programming and Scripting

Need help to change values in XML using Python? noob help pls!

Hello I am a noob in XML and Python. I am trying to do this for my MSc project about a network simulation and need some help.... I want to change the values shown below: <num_crash_failures>1</num_crash_failures> −<crash_failure_entry> <freeze_at_slot>0</freeze_at_slot>... (0 Replies)
Discussion started by: erhanasd
0 Replies

8. Shell Programming and Scripting

Need help to change XML values with shell scripting for Network Simulation

Hello, I don't have experience in this scripting and I need some help to read a value from an XML file and change it with a random number to use in simulator for different network scenarios. </Description><sim_comm_rounds>35</sim_comm_rounds><num_clusters>1</num_clusters><Clocking> I want to... (5 Replies)
Discussion started by: erhanasd
5 Replies

9. Shell Programming and Scripting

KSH Script to Get the <TAG Values> from an XML file

Hi All, I am new to Unix I need a KSH script to get the values from XML file to write to a temp file. Like the requirement is from the below TAG <MAPPING DESCRIPTION ="Test Mapping" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1"> I need the MAPPING DESCRIPTION... (3 Replies)
Discussion started by: perlamohan
3 Replies

10. Shell Programming and Scripting

Parsing and getting data from XML file using ksh script

Hi All, I have a xml file for example as described below <xml> <address> <street><street> <address/> <isbn>426728783932020308393930303</isbn> <book> <name> </name> </book> . . . </xml> My problem is to get the isbn number from the above described file using ksh script. Could... (6 Replies)
Discussion started by: vinna
6 Replies
Login or Register to Ask a Question