Created
May 22, 2013 09:48
-
-
Save anthonysterling/5626456 to your computer and use it in GitHub Desktop.
Finds all running Vagrant instances, recursively, from with in the current folder. It then shuts them down, deletes the VM, and removes the .vagrant file.
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
#!/usr/bin/env bash | |
for config in `find . -type f -name .vagrant` | |
do | |
uuid=`cat "$config" | php -r 'echo json_decode(fgets(STDIN))->active->default;'` | |
if VBoxManage showvminfo $uuid > /dev/null 2>&1; then | |
if VBoxManage showvminfo $uuid --machinereadable | egrep -q 'VMState="running|paused|stuck"'; then | |
VBoxManage controlvm $uuid poweroff | |
fi | |
VBoxManage unregistervm $uuid --delete | |
rm -f "$config" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment