Last active
August 29, 2015 14:18
-
-
Save colby/f98cbc2380db0be48bbb to your computer and use it in GitHub Desktop.
Sandman: A bash script to find all known Vagrant VMs and put them to sleeps. Zzz.
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 | |
# variables | |
vagrant="" | |
# functions | |
errcho() { | |
>&2 echo "$*" | |
exit 1 | |
} | |
check() { | |
which "$1" || errcho "Missing dependency: $1" | |
} | |
# deps | |
vagrant=$(check vagrant) | |
# main | |
printf "Putting VMs to bed. " | |
while read line | |
do | |
set -- $line | |
# 1:a8533bc 2:utility 3:virtualbox 4:poweroff 5:/Users/colbyolson/src/Work/misc/chef | |
[ "$4" = 'running' ] && $vagrant halt $1 | |
printf "z" | |
done < <($vagrant global-status --prune) | |
printf "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works swell. I think adding an option to specify either
halt
or `suspend would be helpful. I'll see if I can add it somehow but I'm not making any promises...