-
-
Save cgarvis/1281358 to your computer and use it in GitHub Desktop.
Commandline for starting/stopping vboxes in headless mode
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 | |
E_NOARGS=85 | |
if [[ -z "$1" || -z "$2" ]]; then | |
[[ "$1" == "list" ]] || ( echo "Usage: `basename $0` [list|start|pause|stop] vm-name"; exit $E_NOARGS; ) | |
fi | |
case $1 in | |
"list" | "ls" ) | |
echo `VBoxManage list runningvms|cut -d"\"" -f2` | |
;; | |
"start" ) | |
running=`VBoxManage list runningvms|cut -d"\"" -f2|grep "^$2$"` | |
if [[ -n $running ]]; then | |
echo "VM Guest \"$2\" is already running" | |
exit 1 | |
else | |
VBoxManage startvm $2 --type headless | |
fi | |
;; | |
"pause" ) | |
running=`VBoxManage list runningvms|cut -d"\"" -f2|grep "^$2$"` | |
if [[ -n $running ]]; then | |
VBoxManage controlvm "$2" savestate | |
else | |
echo "VM Guest \"$2\" is not running!" | |
exit 1 | |
fi | |
;; | |
"stop" ) | |
running=`VBoxManage list runningvms|cut -d"\"" -f2|grep "^$2$"` | |
if [[ -n $running ]]; then | |
VBoxManage controlvm "$2" poweroff | |
else | |
echo "VM Guest \"$2\" is not running!" | |
fi | |
;; | |
* ) | |
echo "Usage: `basename $0` [list|start|pause|stop] vm-name"; exit $E_NOARGS; | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment