24

How can I tell from the command line if a specific virtual machine is up and running from the command line?

  • 3
    vboxmanage list runningvms – slm Mar 23 '18 at 3:03
16
vboxmanage list vms

Dos not (anymore?) tells if the vm is runing or not. It list also not running ones.

vboxmanage showvminfo "your_vm_name" | grep -c "running (since"

Will returns 1 if it's running, or 0 if not.

  • 1
    Also, if ! VBoxManage showvminfo VMNAME --machinereadable | egrep '^VMState="poweroff"$' > /dev/null; then ... – x-yuri Oct 16 '16 at 21:10
  • on Windows use vboxmanage showvminfo "vmname or GUID" | findstr /c:"running (since" – phuclv Nov 11 '16 at 10:21
  • 3
    vboxmanage list runningvms – slm Mar 23 '18 at 3:03
9

If you want a list of all VMs to see if they are running or not use this command:

vboxmanage list vms --long | grep -e "Name:" -e "State:"

This will show the VMs name in one line and its status in the following line such as in

Name:            windows10pro
State:           running (since 2017-06-09T09:16:46.593000000)
Name:            ubuntu16LTS
State:           powered off (since 2017-02-09T19:11:33.000000000)
Name:            zammad
State:           running (since 2017-06-09T09:08:13.871000000)
  • The output from this includes info on any shared folders you might have set up. Pipe to another grep to remove it: ... | grep -v -e 'Host path:' – Doug Thompson Nov 9 '17 at 15:53
  • This also shows PAUSED machines, "list runningvms" thinks that paused machines are running which can be a little confusing... – Samuel Åslund Jun 25 at 7:48
5

This command outputs the list of running vms (tested on Virtualbox 5.1)

VBoxManage list runningvms

To know if a vm is running, this command should do the job (return 1 if running, 0 otherwise) :

VBoxManage list runningvms | sed -r 's/^"(.*)".*$/\1/' | grep 'VM Name' | wc -l
  • A paused machine shows up as running with "list runningvms" this can be rather confusing when troubleshooting! – Samuel Åslund Jun 25 at 7:50
1

I believe you can get this information using VBoxManage (command-line interface to VirtualBox).

You can use The showvminfo command for show information about a particular virtual machine.

This is the same information as VBoxManage list vms would show for all virtual machines.

1

Combining VBoxManage list runningvms with grep alone without anything else will not only give a console output, but will also provide the return code required for shell scripting needs. The grep command will require the exact double quote for the VM in the case where a vm name is provided: example:

$ VBoxManage list runningvms |grep '"demo_vm"'
$ echo $?
1

For a running one

$ VBoxManage list runningvms |grep '"demo_vm_on"'
"demo_vm_on" {bbff5c0e-f8d4-4751-8d34-c53c4b191613}
$ echo $?
0

In the other answer where sed was used to eliminate the double quotes, or if the grep was done without the double quotes, false positives will be returned. Demonstration:

$ VBoxManage list runningvms |grep demo_vm
"demo_vm_on" {bbff5c0e-f8d4-4751-8d34-c53c4b191613}
$ echo $?
0
0

root@yourshell#vboxmanage list vms

Also, see this document.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.