Skip to content

Instantly share code, notes, and snippets.

@colby
Last active January 14, 2016 07:09
Show Gist options
  • Save colby/063ad9ea08c5013cf252 to your computer and use it in GitHub Desktop.
Save colby/063ad9ea08c5013cf252 to your computer and use it in GitHub Desktop.
A tool to put all known Vagrant VMs to sleep.
#!/usr/bin/env sh
# functions
errcho() {
>&2 echo "$*"
exit 1
}
check() {
which "$1" || errcho "Missing dependency: $1"
}
# check deps and store paths
vagrant=$(check vagrant)
grep=$(check grep)
# supply the Vagrant VM index or use default
if [ -z "$1" ]; then
index="$HOME/.vagrant.d/data/machine-index/index"
else
index="$1"
fi
printf "Putting VMs to bed. "
tr ',' \\n < "$index" | $grep 'vagrantfile_path' | cut -d'"' -f4 | xargs -I X sh -c "test -d X && cd X && $vagrant halt > /dev/null 2>&1; printf 'z'"
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment