diff options
| author | hc <hc@email.ch> | 2025-01-02 09:26:32 +0800 |
|---|---|---|
| committer | hc <hc@email.ch> | 2025-01-02 09:26:32 +0800 |
| commit | c33f0979f0312e7a6d43645aa0a5d5b1481751f5 (patch) | |
| tree | 49bd07cf9b6f02572586d22f3794da007bf794d1 /others/vm3/compute/rm.sh | |
| parent | 181bc10748cd9162e85f16722d6c83ff04a2d39d (diff) | |
udpated
Diffstat (limited to 'others/vm3/compute/rm.sh')
| -rwxr-xr-x | others/vm3/compute/rm.sh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/others/vm3/compute/rm.sh b/others/vm3/compute/rm.sh new file mode 100755 index 0000000..f77831c --- /dev/null +++ b/others/vm3/compute/rm.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Check if VMs are provided +if [ $# -eq 0 ]; then + echo "Error: No VM names provided. Usage: $0 vm1 vm2 vm3" + exit 1 +fi + +# List VMs to be removed +echo "The following VMs will be permanently destroyed:" +for vm in "$@"; do + echo "- $vm" +done + +# Confirmation prompt +read -p "Are you sure you want to remove these VMs? (y/N): " confirmation +if [[ ! "$confirmation" =~ ^[Yy]$ ]]; then + echo "Operation cancelled." + exit 1 +fi + +for vm in "$@"; do + sudo virsh destroy "$vm" &>/dev/null + sudo virsh undefine "$vm" --remove-all-storage &>/dev/null + #sudo rm -rf "/var/lib/libvirt/images/${vm}" &>/dev/null + printf "%-50s%10s\n" "Removing $vm..." $([[ $? -eq 0 ]] && echo "Successful" || echo "Failed") +done |
