Skip to content

Instantly share code, notes, and snippets.

@flavio-fernandes
Created August 13, 2018 11:03
Show Gist options
  • Save flavio-fernandes/a773842c5b6748992482d74d6c1cb543 to your computer and use it in GitHub Desktop.
Save flavio-fernandes/a773842c5b6748992482d74d6c1cb543 to your computer and use it in GitHub Desktop.
#!/bin/bash
virt-addr() {
VM="$1"
vm_mac=$(virsh dumpxml $VM | grep "mac address" | sed "s/.*'\(.*\)'.*/\1/g")
arp -an | grep "${vm_mac}" | awk '{ gsub(/[\(\)]/,"",$2); print $2 }'
}
for x in $(virsh list --all | awk '{ if (NR > 2 && $2 != "") {print $2} }') ; do \
v=$(virsh vncdisplay $x 2> /dev/null || true)
vip=$(virt-addr $x 2> /dev/null || true)
echo "vm name: $x vnc: ${v:--} ip: ${vip:--}"
virsh domiflist $x | awk '{ if (NR > 2) {print $0} }'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment