-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestroy_vms.sh
executable file
·21 lines (21 loc) · 1.04 KB
/
destroy_vms.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
MODULE_NAME=shutit_docker_slim
if [[ $(command -v VBoxManage) != '' ]]
then
while true
do
VBoxManage list runningvms | grep ${MODULE_NAME} | awk '{print $1}' | xargs -IXXX VBoxManage controlvm 'XXX' poweroff && VBoxManage list vms | grep ${MODULE_NAME} | awk '{print $1}' | xargs -IXXX VBoxManage unregistervm 'XXX' --delete
# The xargs removes whitespace
if [[ $(VBoxManage list vms | grep ${MODULE_NAME} | wc -l | xargs) -eq '0' ]]
then
break
else
ps -ef | grep virtualbox | grep ${MODULE_NAME} | awk '{print $2}' | xargs kill
sleep 10
fi
done
fi
if [[ $(command -v virsh) ]] && [[ $(kvm-ok 2>&1 | command grep 'can be used') != '' ]]
then
virsh list | grep ${MODULE_NAME} | awk '{print $1}' | xargs -n1 virsh destroy
fi