You are here: Home Development PHP PHP CLI: Virtual Box Startup Script
PHP CLI: Virtual Box Startup Script PDF Print E-mail
User Rating: / 0
PoorBest 
Development - PHP
Written by Rick   
Tuesday, 10 November 2009 18:00

Administrators are often called upon to write scripts to accomplish tasks. I've been playing a lot with php cli scripting lately and had a need to create a script to startup a VirtualBox VM from the command line. Here's what it looks like;

#!/usr/bin/php
<?php
if ($argv[1]=="") {
echo "Options not specified.\n\r";
echo "Usage: ";
echo $argv[0]." <vmname>\n\r\n\r";
exit;
}else{
$vm=$argv[1];
system("VBoxManage vmstatistics ". $vm,$retval);
if ($retval==1) {
echo "Starting Virtual Machine ".$vm."\r\n";
#system("VBoxVRDP -startvm ".$vm,$rval);
system("VBoxManage startvm ".$vm." --type headless",$rval);
}else{
echo $vm." appears to be running already!\r\n";
exit;
}
}
?>

I found using VboxVRDP and VBoxHeadless left the script incomplete and open even after shutting down the virtual machine. I've left a commented line with the VBoxVRDP startup statement for your testing purposes.

Comments (0)
Write comment
Your Contact Details:
Gravatar enabled
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):S
:!::?::idea::arrow:
Security
Please input the anti-spam code that you can read in the image.