This little one liner grabs the lines that define the vnc ports used by all defined on a node (hypervisor) and returns them as a tab delimited string.
grep vnc /etc/libvirt/qemu/*.xml |\ perl -lane 'BEGIN{$,="\t"} m/^.*\/([^\/]+)\.xml:.*port=.(\d{4})/; print $1,$2;'
We use vnc on our libvirt domains, basically because we're familiar with vnc. When a domain is misbehaving, we use ssh port forwarding to redirect from our workstation to the domain virtual screen. However, it takes a few minutes each time to figure out which VNC port the domain in question uses.
Instead, I wanted to record this in our copy of CAMP, and since it has a tab delimited text file importer, wanted the domain name and vnc port separated by a tab.
The same could be accomplished by just saving it as a spreadsheet.
libvirt (virsh) stores it's domain (virtual) definitions in /etc/libvirt/qemu/*.xml. The grep command only returns those lines (along with the file name) in the form
/etc/libvirt/qemu/andrei.dailydata.noc.xml: <graphics type='vnc' port='5917' autoport='no' listen='127.0.0.1'>
We then pass those lines to a Perl one liner which grabs the filename (without the .xml) and the port, then prints them to STDOUT, tab separated. Using the -n flag to perl turns the one liner into a filter, which will run the code on all lines received via STDIN. For the above line, the following is sent to STDOUT
andrei.dailydata.noc 5917