Skip to content

Instantly share code, notes, and snippets.

@colby
Created November 17, 2016 05:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colby/b05ac014968e6dbf4b20bd672dbf4d2f to your computer and use it in GitHub Desktop.
Save colby/b05ac014968e6dbf4b20bd672dbf4d2f to your computer and use it in GitHub Desktop.
Put all of your Vagrant VMs to sleep.
#!/usr/bin/env sh
vagrant=$(which vagrant)
awk=$(which awk)
printf "Gathering a list of machines. "
machines=$(vagrant global-status --prune 2>/dev/null | $awk '/running/ {print $5}')
if [ ! -z "${machines[@]}" ]
then
printf "Putting them to bed. "
for m in ${machines[@]}
do
test -d "$m" && cd "$m" && $vagrant halt > /dev/null 2>&1; printf 'z'
done
printf "\n"
else
printf "They're all asleep!\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment