Get current VirtualBox Status with Vagrant

Viewed 5518

We did alot of stuff with Vagrant in the recent days, and there's a problem we encountered / didn't find any answer to. It's about checking the Status of the VirtualBox with Vagrant, for example:

if config.vmbox_status == 'running'
  # do this stuff
end

If there is any easy way of checking / getting the current Virtual Box status let us know.

5 Answers

Or with the use of awk to get the VM's current state:

VM_STATUS=`vagrant status --machine-readable | grep ",state,"  | awk -F, '{print $4}'`
case "${VM_STATUS}" in
  running)
     echo "RUNNING"
  ;;
  poweroff)
     echo "POWEROFF"
  ;;
  *)
     echo "Unhandled: ${VM_STATUS}"
  ;;
esac
Related