Skip to content

Instantly share code, notes, and snippets.

@cgarvis
Created October 12, 2011 14:29
Show Gist options
  • Save cgarvis/1281358 to your computer and use it in GitHub Desktop.
Save cgarvis/1281358 to your computer and use it in GitHub Desktop.
Commandline for starting/stopping vboxes in headless mode
#!/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