Skip to content

Instantly share code, notes, and snippets.

@mhewedy
Last active January 20, 2020 05:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhewedy/e243d84fb5caee2da2d88dcd3ac4b3ec to your computer and use it in GitHub Desktop.
Save mhewedy/e243d84fb5caee2da2d88dcd3ac4b3ec to your computer and use it in GitHub Desktop.
Virtualbox control cli
#! /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
@mhewedy
Copy link
Author

mhewedy commented Jan 19, 2020

see also vmip.go

@mhewedy
Copy link
Author

mhewedy commented Jan 20, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment