Solved

linux scripts to modify xml files

Posted on 2011-09-07
8
405 Views
Last Modified: 2012-05-12
please suggest a way to use an available linux script which will grab two xml files and substitute some variables.

this script needs to be able to extract the private ip of the system, which is the substituted value for those variables.
0
Comment
Question by:bhomass
  • 4
  • 4
8 Comments
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36500668
Please provide the xml file and which variables you want to substitute.
0
 

Author Comment

by:bhomass
ID: 36500714
they are some tomcat config files, like server.xml

that's say you have one tag that says

<Engine name="Catalina" defaultHost="localhost">

and I remove "localhost" and put in ${ipaddress} >

the script should sub ${ipaddress} with the numeric address like 192.168.1.210, after it reads the numerical address from ifconfig command.
0
 
LVL 38

Accepted Solution

by:
wesly_chen earned 250 total points
ID: 36500775
IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
sed  "s/\${ipaddress}/$IP/g"  server.xml  > server.xml_new
/bin/mv -f  server.xml_new   server.xml
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:bhomass
ID: 36500860
that's looks cool. I will try tomorrow.
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36503063
After
sed  "s/\${ipaddress}/$IP/g"  server.xml  > server.xml_new
verify server.xml_new before "/bin/mv -f"
0
 

Author Comment

by:bhomass
ID: 36514459
ifconfig gives me two addresses

one public, one private. identified as eth0 and eth1


as a result, when I ran

ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}

I get two ip addresses back. How do I get only one, the private one from eth1?
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36514488
ifconfig  eth1| grep 'inet addr:'| cut -d: -f2 | awk '{ print $1}
0
 

Author Comment

by:bhomass
ID: 36514561
worked like a charm!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question