Skip to content

Instantly share code, notes, and snippets.

@bdelespierre
Created October 16, 2013 08:47
Show Gist options
  • Select an option

  • Save bdelespierre/7004662 to your computer and use it in GitHub Desktop.

Select an option

Save bdelespierre/7004662 to your computer and use it in GitHub Desktop.
Easily launch any virtualbox vm in headless mode or stop it using a simple configuration file
#!/bin/bash
function usage {
echo "Usage: $0 [file] [start|stop|status|connect]"
}
if [ -z $1 ]; then
usage
exit 0
fi
if [ ! -f $1 ]; then
echo "No such configuration file $1"
usage
exit -1
fi
source $1
for var in "vm_name" "vm_uuid" "vm_user" "vm_addr"; do
if [ -z ${!var} ]; then
echo "Missing configuration parameter $var"
exit -1
fi
done
case "$2" in
start)
vboxmanage startvm $vm_uuid --type headless
;;
stop)
vboxmanage controlvm $vm_uuid savestate
;;
status)
echo "$vm_name is `vboxmanage showvminfo $vm_uuid | grep State | cut -c18-`"
;;
connect)
([ ! -z $ssh_key ] && ssh -i "$ssh_key" $vm_user@$vm_addr) || ssh $vm_user@$vm_addr
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment