Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am writing a shell script to start a virtualbox (ubuntu). After the command I want to put a for loop to keep checking the status of virtualbox and the script comes out of the loop only after the ubuntu is fully started. Something like

vboxmanage starvm Ubuntu

for (i= 0; i < 100; i++)
{
continue if (vbox is not on)
}

exit when vbox is fully on and execute the next command

share|improve this question
    
Actually I want to know if there is any command from which we can check the status of the machine because after Ubuntu is booted, I want ssh connection to it. –  Asbat Jun 13 '13 at 11:03

2 Answers 2

up vote 1 down vote accepted

We can use VBoxManage to query the state of a Virtual Machine. The following command will list all running virtual machines on your system:

VBoxManage list runningvms

The output will show you the following information which you can then further parse in your script:

"name_of_machine" <UUID>

This will of course not tell you whether the guest OS had booted properly, or is ready to use. For such informations you may need to run a script on the guest starting after boot to send it's running state to the host.

share|improve this answer
    
Yes you are right for that purpose we need to have a script inside the guest OS. They also suggest the same thing forums.virtualbox.org/viewtopic.php?f=1&t=50241. Since my next command in the script is to ssh the guest OS after boot therefore I will check if I add it in the loop and continue untill connection is established to the guest os. –  Asbat Jun 13 '13 at 11:55

I know its a bit late to answer that question. but it might help others. you can run the following command to get the state of your Virtual machine

VBoxManage list vms -l | grep -e Name: -e State

it will tell you all of the virtual machines along with their status. run this command in your loop, check each machine status.

if( stopped || paused ) 
VBoxManage startvm VMNAME           //here VMNAME is variable containing name of your vm
else
//do nothing

do it for all your vms. i hope it helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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