Skip to content

Instantly share code, notes, and snippets.

@Ragnarokkr
Created June 2, 2013 15:54
Show Gist options
  • Save Ragnarokkr/5693919 to your computer and use it in GitHub Desktop.
Save Ragnarokkr/5693919 to your computer and use it in GitHub Desktop.
Simple function to search for a valid VirtualBox VM and return its UUID
#!/usr/bin/env sh
# Searches for a currently available VirtualBox VM and returns its UUID.
#
# Code by Marco Trulla a.k.a. Ragnarøkkr
# http://marcotrulla.it/
# http://github.com/Ragnarokkr
#
# Params:
# $1 => the regex pattern to search for in currently available virtual machines
# (case sensitive).
#
# Returns:
# the VM's UUID or nothing.
#
# Example:
#
# VBoxHeadless -s `vbox-query-uuid "Ubuntu Server 13.04"`
vbox-query-uuid () {
local uuid=$(VBoxManage list vms | egrep "$1" | sed -e 's/.*{\(.*\)}.*/\1/g')
echo $uuid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment