2

If I use wbemcli to enumerate all the instances I get something similar to this:

wbemcli -nl -t -noverify ei 'https://aaa/aaa:aaa' 
https://aaa/aaa:aaa.Version="",Vendor="",Name=""
-Version#=""
-Vendor#=""
-Name#=""
-Description=""

How can I call wbemcli to get only one item (i.e. the Name)? and not everything.

The -t option says:

-t
Append array ([]), reference (&) and key property (#) indicators to property names

but I wasn't able to utilize this in my favor.

Is there a way to retrieve this information in a key/value pair format?
Or maybe pipe the output into an array or something from which I can grab only what I need?

When I drop the output into an array all the data is stored in the first element ${a[0]}.

EDIT Here's an output example:

$ wbemcli -nl -t -noverify ei 'https://user:pw@000.000.000.000:0000/root/aaa:AA_AaaAaaaAaaaa'
000.000.000.000:0000/root/aaa:AA_AaaAaaaAaaaa.ClassName="AA_AaaAaaaAaaaa",Name="123456a7ff890123"
-ClassName#="AA_AaaAaaaAaaaa"
-Name#="123456a7ff890123"
-Caption="aa aaa"
-Description="aa aa"
-ElementName="aa aaa aaaa"
-OperationalStatus[]=2
-HealthState=5
-CommunicationStatus=2
-DetailedStatus=1
-OperatingStatus=0
-PrimaryStatus=1
-EnabledState=5
-RequestedState=12
-EnabledDefault=2
-TransitioningToState=12
-PrimaryOwnerName="Uninitialized Contact"
-PrimaryOwnerContact="Uninitialized Contact"

The output is usually in this format.
If the query returns multiple objects they will be grouped and all will have the same members with their appropriate values.

slybloty
  • 6,346
  • 6
  • 49
  • 70
  • Are the values on the lines prefixed with `-` just duplicating the values on the line starting with `https`? Does the output always look like this? Can you run this on multiple URLs at once (and have need to retrieve each `Name` value independently)? – Etan Reisner Dec 23 '15 at 13:02
  • @EtanReisner I edited my post to reflect your questions. – slybloty Dec 23 '15 at 17:52
  • 1
    Pipe that to `awk -F '[-=]' '$1==Name{print $2}'`? (Assuming neither `-` nor `=` can appear in the keys or values. If it can then you need slightly more than that.) – Etan Reisner Dec 23 '15 at 18:01

1 Answers1

1

http://linux.dell.com/files/whitepapers/WBEM_based_management_in_Linux.pdf has a number of examples which simply suggest to use grep to obtain the specific key and value you are looking for. There does not seem to be a way to directly query for a specific key within a result set.

Expanding on the comment by Etan Reisner, you could use something like

wbemcli <<query>> | grep -oP "^-$key=\K.*"

to obtain the value for the key named in $key, provided you have GNU grep which provides the -P option for Perl-compatible regular expressions (here, the \K "forget up through here" operator is useful). So for your specific example,

wbemcli -nl -t -noverify ei 'https://aaa/aaa:aaa' |
grep -oP '^-Name#=\K.*'

There is also a -dx option which produces XML output, which may be more robust if you are planning to write a major application on top of this protocol (but then perhaps you should be looking at a dedicated WBEM library such as the C or Java libraries listed in their wiki). It would not seem to be implausible to write a simple (e.g.) Python client to retrieve (part of?) the result tree and let you query or manipulate it locally, either.

tripleee
  • 175,061
  • 34
  • 275
  • 318