Created
May 23, 2017 20:09
-
-
Save davydany/8f4dd4622aedfa9552e7db1a057274c8 to your computer and use it in GitHub Desktop.
Destroy all running VirtualBox VMs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Runs perfectly on CentOS 7 | |
| # Read all pids for "VBoxHeadless" process, and kill (-9) them. | |
| while read -r pid; do | |
| echo "Killing VirtualBox Process '${pid}'..." | |
| kill -9 ${pid} | |
| echo " OK Done." | |
| done < <(pgrep VBoxHeadless) | |
| # Read all VirtualBox VMs, and unregister, then delete them | |
| while read -r name; do | |
| echo "Unregistering VM '$(echo $name |awk '{print$2}' |sed -e 's/.*{\([^}]\+\)}.*/\1/g')'..." | |
| VBoxManage unregistervm "$(echo $name |awk '{print$2}' |sed -e 's/.*{\([^}]\+\)}.*/\1/g')" --delete &> /dev/null | |
| done < <(VBoxManage list vms) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment