VirtualBox 3.1 Naming scheme
Brought to you by:
markbaa
I noticed that when I had a USB printer plugged in and attached to a VM, I was unable to shutdown a given VM. I tracked it down to how the VM's name was being pulled out.
name=$($vbox_command showvminfo $uuid | grep "Name:" | awk 'BEGIN{FS="Name: "}{print $2}')
This returns 2 results in this variable when you have a USB device plugged in. Using the --machinereadable switch seems to work around that behavior. I've attached a diff that works for 3.1, I have no other version of VirtualBox to try with. I haven't looked to see when that switch was added.
I've been frustrated by this problem for awhile but just started looking into the cause. The problem is that in recent versions (3.?.?), showvminfo returns multiple lines starting with "Name:". Your suggestion of using --machinereadable works, but may not be compatible with earlier versions of VirtualBox. Since we are only interested in the first occurance of "Name:", the simplest fix is to pipe the vm info through 'head'.
name=$($vbox_command showvminfo $uuid | head | grep "Name:" | awk 'BEGIN{FS="Name: "}{print $2}')
I've only tested this with VirtualBox 3.1.6, but I'm guessing it would be backward compatible as long as the vm name appears in the first five lines of output.
I am still experiencing a problem managing an XP client running on Ubuntu with VirtualBox 3.1.6. With the suggested change to parse the output of showvminfo, I can login remotely via ssh and start/stop the virtual XP machine. However if I login via rdesktop and then shutdown the vm, I lose the ability to remotely restart it. After this happens, I can only restart the vm from a local session on the Ubuntu server. It isn't a problem with vboxtool, because VBoxManage won't restart the vm through ssh either. I only mention it here in case others are seeing the same problem.