Skip to content

Instantly share code, notes, and snippets.

@scarolan
Last active December 18, 2015 11:29
Show Gist options
  • Save scarolan/5775596 to your computer and use it in GitHub Desktop.
Save scarolan/5775596 to your computer and use it in GitHub Desktop.
"vlist" and "vssh" commands for working with Vagrant virtual machines. Drop these in your .bashrc. vlist creates a list of all your running VMs. vssh loops through all your VMs, and attempts to run commands on each of them.
# vlist generates a list of running Vagrant VMs
vlist ()
{
vagrant status | awk '/running/{ print $1 }'
}
# vssh runs your command(s) on all VMs. Enclose in quotes to run multiple commands.
vssh ()
{
[ $# -ne 1 ] && (echo "Usage: vssh command"; return 1)
command="$1";
for host in $(vlist);
do
vagrant ssh $host -c "$command";
done
}
@scarolan
Copy link
Author

Updated to properly parse multiple commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment