Created
October 16, 2013 08:47
-
-
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
This file contains hidden or 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/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