Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- vm_status=""
- vm_port=""
- divider='========================='
- divider=$divider$divider
- header="\n %-10s %-10s %-10s \n"
- format=" %-10s %-10s %-10s\n"
- width=35
- printf "$header" "VM_NAME" "VM_STATUS" "VNC_PORT"
- printf "%$width.${width}s\n" "$divider"
- PRINT ()
- {
- printf "$format" \
- "$1" "$2" "$3"
- }
- ## find ALL EXISTING VMs
- for existing_vm in $(find /etc/libvirt/qemu/ -maxdepth 1 -type f -name *.xml -printf "%f\n" | cut -d '.' -f 1)
- do
- ## find and subtract ACTIVE VMs
- active_vms=$(find /var/run/libvirt/qemu/ -maxdepth 1 -type f -name *.xml -printf "%f\n" | cut -d '.' -f 1)
- is_active=$(echo $active_vms | grep $existing_vm)
- if [ ! -z "$is_active" ];
- then
- ## VM IST ONLINE
- #cat /var/run/libvirt/qemu/$existing_vm.xml | grep -E 'graphics type|domstatus state'
- vm_status=$(cat /var/run/libvirt/qemu/$existing_vm.xml | grep -ohE "domstatus state='.*'" | cut -d \' -f 2)
- vm_port=$(cat /var/run/libvirt/qemu/$existing_vm.xml | grep 'graphics type' | grep -ohE "port='....'" | cut -d \' -f 2)
- PRINT "$existing_vm" "$vm_status" "$vm_port"
- else
- ## VM IST OFFLINE
- PRINT "$existing_vm" "OFFLINE" "NaN"
- fi
- ## RESET of variables just to play it safe
- vm_status=""
- vm_port=""
- is_active=""
- done
- echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement