A script that on a proxmox node, will list the ip addresses of running virtual machines.
install required packages :
apt-get install net-tools arp-scan
make the above script executable
chmod +x get_ips_of_vms.sh
run the script
./get_ips_of_vms.sh
resulting in something like :
# ./get_ips_of_vms.sh
192.168.22.131 k8s-master 200-k8s-master
192.168.22.132 k8s-worker01 201-k8s-worker01
192.168.22.133 k8s-worker02 202-k8s-worker02
This is useful, thank you. I noticed a scenario in my environment where I grep with
$id, and that value appeared elsewhere in the line as the PID. My$idvalue was 130, and I had a VM with a running PID of 1381306 in this case. By the time it reached setting$mac, I had a repeated name row with no other values returned.As a workaround for the moment, i've swapped the grep and awk, so it strips out the PID column that might give false matches:
name=$(qm list | grep -v stopped | awk '{print $1" "$2}' | grep $id)I then just split the Name from the ID separately after