-
-
Save mhewedy/e243d84fb5caee2da2d88dcd3ac4b3ec to your computer and use it in GitHub Desktop.
Virtualbox control cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
case $1 in | |
list) | |
vboxmanage list vms | |
;; | |
ps) | |
vboxmanage list runningvms | |
;; | |
create) | |
# template file name: ubuntu-01.ova (name: ubuntu-01) | |
next=$(($(vboxmanage list vms | sort | tail -n 1 | cut -d " " -f1 | cut -d "\"" -f2 | cut -d "-" -f2)+1)) | |
vboxmanage import $2 --vsys 0 --vmname "ubuntu-$(printf %02d $next)" | |
;; | |
delete) | |
vboxmanage controlvm $2 poweroff | |
VBoxManage unregistervm $2 --delete | |
;; | |
start) | |
vboxmanage startvm $2 --type headless | |
sleep 20 # sleep while vm starts | |
vmip $2 # see https://gist.github.com/mhewedy/352ddb55d4740945d0462df91aece198 | |
while [ $? -ne 0 ]; do vmip $2; done | |
;; | |
stop) | |
vboxmanage controlvm $2 poweroff | |
;; | |
*) | |
echo "usage vm (list|ps|create|delete|start|stop) [options]" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see also vmip.go