Skip to content

Instantly share code, notes, and snippets.

@heatxsink
Last active May 28, 2019 12:46
Show Gist options
  • Save heatxsink/5103511 to your computer and use it in GitHub Desktop.
Save heatxsink/5103511 to your computer and use it in GitHub Desktop.
#!/bin/bash
###
#
# Wrap the weird VirtualBox commandline for headless vms
#
###
CMD_HEADLESS=`which VBoxHeadless`;
CMD_MANAGE=`which VBoxManage`;
if [ "$CMD_HEADLESS" = "" ]; then
echo "No VBoxHeadless installed";
exit 1;
fi;
if [ "$CMD_MANAGE" = "" ]; then
echo "No VBoxManage installed";
exit 1;
fi;
case "$1" in
on)
echo "Starting $2"
`nohup $CMD_HEADLESS -startvm $2` &
;;
off)
echo "Turning off $2"
$CMD_MANAGE controlvm $2 poweroff
;;
shutdown)
echo "Sending shutdown signal to $2"
$CMD_MANAGE controlvm $2 acpipowerbutton
;;
reset)
echo "Resetting $2"
$CMD_MANAGE controlvm $2 reset
;;
pause)
echo "Pausing $2"
$CMD_MANAGE controlvm $2 pause
;;
resume)
echo "Resuming $2"
$CMD_MANAGE controlvm $2 resume
;;
list)
echo "Listing all vms..."
$CMD_MANAGE list vms
;;
status)
echo "Listing all running vms ..."
$CMD_MANAGE list runningvms
;;
*)
echo "Usage: $NAME {on|off|shutdown|reset|pause|resume|status|list} [vm_name]"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment