#!/bin/bash
time qm list |column -t
for vmid in $(qm list |grep running |awk '{print $1}'); do
echo "$(date) - Checking $vmid"
qm agent $vmid ping; rc=$?
if [ $rc -gt 0 ]; then
echo "$vmid guest agent not responding!"
continue;
fi
qm guest cmd $vmid get-host-name |tr -d '{}' |awk 'NF>0'
qm guest cmd $vmid network-get-interfaces |grep ip-address
done >/tmp/vm-ips.txt
# grep / less /tmp/vm-ips.txt and find IP , surrounding text will give you hostname
# parsing complete JSON output is up to you
# Be aware that querying the guest agent is sometimes not reliable, if you limit the VM's cpu resources it can time out even if the agent is running
# Feel free to request this as a feature in the proxmox bug tracker, would come in handy in the GUI