virtualbox script to control Virtual Machines

Additional to my daily job, I need to “play” from time to time in my home server, it’s a quad core machine with 8 gigs of RAM and two hard drives, nothing special about it, the important thing is that it does the job.

About 8 month ago I upgraded the OS and VMWare server started to “complain”, specially the graphical interface, it was discontinued and almost dead, so I decided to move to VirtualBox, I also updated the OS to Oracle Linux 6.

I’m surprised on how complete VirtualBox is and the multiple configuration options available, the graphical interface just doesn’t make justice to the product.

I started creating virtual machines to test my new toy and I realized that when the virtual machines are started from the graphical interface (I use gnome) they have a “collateral” impact on the host performance, having that GUI interface sitting there cost cpu and memory, after that I understood the importance on correctly setting the “VRDE” (Virtual Box Remote Desktop Extension), let me tell you something, it really rocks.
VRDE allows you to connect to your machines, linux, windows or whatever, using your normal Windows remote desktop connection, is a true console that works even if the virtual machine you are connecting to have no network.

I want to share with you a script that I developed using bash shell scripting to control machines on VirtualBox 4, I call it vbctl (VirtualBox control), and it really helps controlling the machines states (startup, pause,shutdown ,save state, etc).

– It will scan the virtual machines in the system and list them (screenshot 1).
– It will allow you to perform operations on them (screenshot 2).
– Designed for headless machines, it will only start headless machines and it will show the RDC port (VRDE Port) in the listing (screenshot 1).
– VRDE activation, if you start a machine with VRDE disabled it will enable it and ask for a port number (between 5000 and 5050).

I want to state that this is not an intelligent script, it will do whatever you ask it to do (with some minor exceptions), for example, it will allow you to shut down a machine that’s already down.

Installation instructions:
– Create a directory (with the virtualbox administrator user).
– Save the script as
– chmod 740
– edit your .bash_profile and create an alias (optional)
alias vbctl=’/<path>/’

Click to enlarge

Screenshot 1 – Click to enlarge

click to enlarge

screenshot2 – Click to enlarge

One last thing, if you improve this script please share it back!



Well, the OperSource spirit arrived sooner than I expected.

In less than two weeks I received the first important improvement!

  • V1.3  can now be downloaded from here

Mr. João Figueiredo improved the visual presentation and added colors! he also fixed minor problem when Virtual machine names have spaces.

Please visit his website for screenshots and details or download the script directly from his website.

Version 1.2 is still available for download.

This entry was posted in Linux/Unix, Oracle Server, Virtualization and tagged , , , . Bookmark the permalink.

6 Responses to virtualbox script to control Virtual Machines

  1. Pingback: virtualbox script to control Virtual Machines | Oracle Examples | Linux Blog

  2. Joao says:

    Carlos, this script does exactly what I need: controls virtualbox machines from the command line. While testing it I found and corrected a minor issue with machines having white spaces in their names. I also changed the way it looks by adding color. The new version is available on my website at if you want to try it. Thanks for sharing your work.

    • Hi Joao, it was so nice to see my script redesigned with colors, that was major makeup job you did!, thanks also for solving the problem when the names have spaces. I’m using the “overhauled” version now 🙂
      Thanks for sharing

  3. João L. M. says:

    Very nice.

  4. Sofia says:

    Congratulations Carlos and Joao!. Very good script. We add two more functions cloning and destruction of vms. You can spend your mails to send the scripts. I haven’t website to publish it. I would like to contribute to the community. 🙂
    Thanks for sharing.

  5. pobrika says:

    I searched for a script to do this and could not find one so for the last few days I’ve been gradually writing my own, whilst researching various options I wanted I ran into your script.
    First off that looks great and does more than I was initially thinking and doing in mine.
    Second I feel I’ve wasted the last few days scripting something that was already out there I knew there must be one somewhere! A good Linux admin does not reinvent the wheel!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s