From 3a52e92fbbbab4df949740f89a389d68281a9428 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 22 May 2025 18:36:01 +0800 Subject: hehe --- others/vm3/compute/ls.sh | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100755 others/vm3/compute/ls.sh (limited to 'others/vm3/compute/ls.sh') diff --git a/others/vm3/compute/ls.sh b/others/vm3/compute/ls.sh deleted file mode 100755 index b821fd1..0000000 --- a/others/vm3/compute/ls.sh +++ /dev/null @@ -1,45 +0,0 @@ - -#!/bin/bash -printf "%-10s %-15s %-8s %-6s %-8s %-12s %-10s\n" "Network" "IP" "State" "vCPUs" "RAM(GB)" "Disk(GB)" "Name" -printf "%-10s %-15s %-8s %-6s %-8s %-12s %-10s\n" "----------" "---------------" "--------" "-----" "-------" "-----------" "----------" - -# Get all VMs -vms=$(sudo virsh list --name --all) - -# Cache the network leases once -default_leases=$(sudo virsh net-dhcp-leases default 2>/dev/null) - -for vm in $vms; do - # Get XML once and use it multiple times - xml=$(sudo virsh dumpxml "$vm" 2>/dev/null) - - # Extract all data from the cached XML - mac=$(echo "$xml" | grep "mac address" | awk -F\' '{ print $2}') - net=$(echo "$xml" | grep "/dev/null > /tmp/state.$$ & - echo "$xml" | grep "]' '{print $3}' > /tmp/vcpus.$$ & - echo "$xml" | grep "]' '{print $3}' | awk '{ printf "%.2f", $1/1048576 }' > /tmp/ram.$$ & - sudo du -sk "/var/lib/libvirt/images/${vm}.qcow2" 2>/dev/null | awk '{ printf "%.2f", $1/1024/1024 }' > /tmp/disk.$$ & - - wait - - # Read from temp files - state=$(cat /tmp/state.$$ 2>/dev/null) - vcpus=$(cat /tmp/vcpus.$$ 2>/dev/null) - ram=$(cat /tmp/ram.$$ 2>/dev/null) - disk=$(cat /tmp/disk.$$ 2>/dev/null) - - # Clean up temp files - rm -f /tmp/state.$$ /tmp/vcpus.$$ /tmp/ram.$$ /tmp/disk.$$ - - printf "%-10s %-15s %-8s %-6s %-8s %-12s %-10s\n" \ - "$net" "$ip" "$state" "$vcpus" "$ram" "$disk" "$vm" -done -- cgit v1.2.3-70-g09d2