Skip to content

Instantly share code, notes, and snippets.

@checco
Created April 8, 2016 15:41
Show Gist options
  • Save checco/39907741fa9e8bc8a7133f969ecbaf1b to your computer and use it in GitHub Desktop.
Save checco/39907741fa9e8bc8a7133f969ecbaf1b to your computer and use it in GitHub Desktop.
Script that return a list of running Vagrant machine (IP HOSTNAME), so you can copy and paste it on your /etc/hosts
#!/bin/bash
interface="eth0"
hosts=`vagrant status | grep running | awk '{print $1}'`
if [ `echo ${hosts} | wc -w` -gt '0' ]
then
for host in ${hosts}
do
ip=`echo "ip a sh dev ${interface} | grep 'inet ' | sed 's/\// /g'" | vagrant ssh ${host} | awk '{print $2}'`
echo -e "${ip}\t ${host}"
done
else
echo "There are no machines running"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment