I've been having some difficulties parsing XML output from the Sun Grid Engine's `qstat` command. Currently, I'm using XML::Smart. However, after creating the XML object and parsing the output (the command outputs a LOT of XML), it will not get all of the data that I want. Here's an example: I run the command qstat -u \* -ext -xml -s r -F:
<?xml version='1.0'?> <job_info ... ?revision=1.11"> <queue_info> <Queue-List> <name>long_zeta@zeta09.local</name> <qtype>BIP</qtype> <slots_used>1</slots_used> <slots_resv>0</slots_resv> <slots_total>8</slots_total> <arch>lx26-amd64</arch> <resource name="arch" type="hl">lx26-amd64</resource> <resource name="num_proc" type="hl">8</resource> ... <job_list state="running"> <JB_job_number>642412</JB_job_number> <JAT_prio>5.00248</JAT_prio> <JAT_ntix>0.00002</JAT_ntix> <JB_name>U6s53097</JB_name> <JB_owner>npatel37</JB_owner> <JB_project>correlat</JB_project> <JB_department>defaultdepartment</JB_department> <state>r</state> <cpu_usage>224919.00000</cpu_usage> <mem_usage>15753.53518</mem_usage> <io_usage>0.32690</io_usage> <tickets>0</tickets> <JB_override_tickets>0</JB_override_tickets> <JB_jobshare>0</JB_jobshare> <otickets>0</otickets> <ftickets>0</ftickets> <stickets>0</stickets> <JAT_share>0.00002</JAT_share> <slots>1</slots> </job_list> </Queue-List> </queue_info> </job_info>
The problem is, I can't get any info under the <job_list> tag, such as <slots>. No matter what I do, the Perl script will return nothing. Here's the code I'm using:
use XML::Smart; my ($xml,$qstat); $qstat=`qstat -u \* -ext -xml -s r -F`; $xml = XML::Smart->new($qstat); foreach ($xml->{job_info}->{queue_info}->{"Queue-List"}('@') ) { print $_->{job_list}->{slots}; }
That script won't print out anything. I've used Data::Dumper and Data::Dump; both printed out the tree exactly as expected, without the <job_list> tag anywhere to be found. I also should point out that, in between the <queue-info> tags, there are many many <Queue-List> tags that may or may not contain a <job_list>. Some have two or three, others have none. However, even Data::Dumper cannot find those, even when I grep for them. Thanks, Ben Olson

In reply to Parsing XML output from `qstat` by Macslayer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.