ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey guys,
I am working on a script to list out attributes of an XML file and then add a new IP to the list of nodes on the load balancer. I have a script that queries the Load Balancer to get it's information. It returns me the following xml file.
I need to figure out how to pull the Load Balancer ID# and the Load Balancer Name. Then I need to Pull the IP address and port number of ever single node on the load balancer. I do not need the IP and port for the load balancer itself. So far I am having trouble figuring out how to do it since everything uses an attribute tag.
Once I get this information I can go from there on adding the new IP and port to the list.
I prefer bash because it is the only scripting language I know. However this API I am using supports Java, PHP, Python, Perl, Ruby, C#, and bash.
The API is a REST system and I am doing a request for info of the load balancer. In the end I need to be able to iterate through all the IP addesses and ports of the nodes on the load balancer so I can add a new one. That is simple as generating the URL and using "curl -f" with the URL. However with a REST system I need to be able to list the Load Balancer ID, all the IPs and Port numbers as well as my authentication info within the URL. So that brings me back to why I am parsing this info to begin with. Crappy API in my opinion, but it is what I have to work with.
I ran it and it seems to just hang. It is probably how I modified your command. I have the xml file located at /tmp/ggapi.list_load_balancer.xml so I modified the command to read this
Code:
echo `grep -A2 name=\"/tmp/ggapi.list_load_balancer.xml` | sed -e 's/.*name="id">\([0-9]\+\)\?.*name="name">\([-a-zA-Z0-9 ._]\+\)\?<.*/LB_ID=\1 LB_NAME=\2/'
I have a feeling that is not correct.
Last edited by worm5252; 03-30-2010 at 09:47 AM.
Reason: correcting case
Bash is completely and utterly inappropriate for parsing out XML files.
Quote:
You can't realistically parse tag-based markup languages like HTML and XML using Bash or utilities such as grep, sed or cut. If you just want to dump/render HTML, see (links|links2|lynx|w3m) -dump, html2text, vilistextum. For parsing out pieces of data, see tidy+(xmlstarlet|xmlgawk|xpath|xml2), or learn xslt. Ask #xml and #html for more help. See http://www.codinghorror.com/blog/archives/001311.html
Well my challege is not that I cant parse it so to speak. The problem is the API provides a poorly structured response. You can see the xml above in my first post, instead of making it structured like <LoadBalancerID></LoadBalancerID> they use
Everything ends up being an attribute of <object name="loadbalancer">. So There is not a real way for me to parse it to obtain information on the load balancer members, the load balncer ID, etc. So thats where bash comes into play. Aside from it is the only language I know
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.