VM-ek listázása

#!/bin/bash
. ovm_functions.sh
kulcs_ellenorzes
OUT_FILE=ovm_list_vm_phys_disks.lst
TMP_FILE=${0}.tmp

echo 'NAME;OS;IP;VCPU;MEMORY;DISK_SIZE_SUM;NETWORKS'
for VM_ID in $(ovm_exec "list vm" "id"); do
    ovm_cli "show vm id=$VM_ID" 2>&1 > ${TMP_FILE}
    NAME=$(cat ${TMP_FILE} | awk -F'=' '/Name/{print $2}')
    MEMORY=$(cat ${TMP_FILE} | grep -v Max | awk -F'=' '/Memory/{print $2}')
    VCPU=$(cat ${TMP_FILE} | grep -v Max | awk -F'=' '/Processors/{print $2}')
    OS=$(cat ${TMP_FILE} | awk -F'=' '/Operating System/{print $2}')
    IP=$(host $NAME | awk '{print $NF}')
    VNIC_NUM=$(cat ${TMP_FILE} | grep -c "Vnic")
    NETWORKS=""
    for ((I=1; I<=$VNIC_NUM; I++)); do
        VNIC_ID=$(cat ${TMP_FILE} | awk '/Vnic '$I'/{print $5}')
        NETWORK_ID=$(ovm_exec "show vnic id=$VNIC_ID" "Network" | awk '{print $1}')
        VLAN_DESC=$(ovm_cli "show network id=$NETWORK_ID" | awk -F'=' '/Description/{print $2}')
        NETWORKS=$NETWORKS","$VLAN_DESC
    done
    VMDISKMAPPING_NUM=$(cat ${TMP_FILE} | grep -c "VmDiskMapping")
    DISK_SIZE_SUM=0
    for ((I=1; I<$VMDISKMAPPING_NUM; I++)); do
        VMDISKMAPPING_ID=$(cat ${TMP_FILE} | awk '/VmDiskMapping '$I'/{print $5}')
        DISK_ID=$(ovm_cli "show vmdiskmapping id=$VMDISKMAPPING_ID" | awk -F'=' '/Disk =/{print $2}' | awk '{print $1}')
        [[ -z "$DISK_ID" ]] && continue;
        if [[ $DISK_ID =~ img$  ]]; then
            DISK_SIZE=$(ovm_exec "show virtualdisk name=$DISK_ID" "Max \(GiB\)")
            DISK_SIZE_SUM=$(echo "scale=2;$DISK_SIZE_SUM + $DISK_SIZE"|bc)
        else
            DISK_SIZE=$(ovm_exec "show physicalDisk id=$DISK_ID" "Size \(GiB\)")
            DISK_SIZE_SUM=$(echo "scale=2;$DISK_SIZE_SUM + $DISK_SIZE"|bc)
        fi
    done
    echo "${NAME# };$OS;$IP;$VCPU;$MEMORY;${DISK_SIZE_SUM%.*} GB;${NETWORKS#, }"
set +x
done
rm $TMP_FILE