Skip to content

Instantly share code, notes, and snippets.

@anthonysterling
Created May 22, 2013 09:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonysterling/5626456 to your computer and use it in GitHub Desktop.
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.
#!/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