Shutdown all running Vagrant boxes
Here's a quick shell script I use to quickly shutdown all running vagrant instances.
$ vagrant global-status | ruby -ane '`cd #{$F[4]} && vagrant halt` if $F[3] == "running"'
Written by Ryan Sonnek
Related protips
5 Responses
That's pretty sweet. Although I've not ever used the $F
array. Is that a file arguments array of some kind?
over 1 year ago
·
$F is a predefined variable when you run ruby -a
. here's more documentation on ruby predefined variables:
http://www.tutorialspoint.com/ruby/ruby_predefined_variables.htm
over 1 year ago
·
That might be a good protip on it's own! :D
over 1 year ago
·
More UNIX-ly variant:
vagrant global-status | awk '$3 == "running"{print $4}' | xargs -I '{}' sh -c 'cd "$1" && vagrant halt'
over 1 year ago
·
At first I liked this, but a quick check by running "vagrant global-status" when I had two separate Vagrant directories running one instance each shows only one instance. This is on OSX Yosemite (10.10), VirtualBox 4.3.18r96516 and Vagrant 1.6.5.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#