-
-
Save charego/cf61e1bee862adea38c352ad418fe523 to your computer and use it in GitHub Desktop.
VirtualBox VM helper
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 | |
VM_NAME='ubuntu-64' | |
vmStart() { | |
# & (the first one) detaches the command from stdin. | |
# >/dev/null detaches the shell session from stdout and stderr. | |
# &disown removes the command from the shell's job list. | |
VBoxHeadless --startvm "${VM_NAME}" &>/dev/null &disown | |
echo "VirtualBox VM started: ${VM_NAME}" | |
} | |
vmStop() { | |
VBoxManage controlvm "${VM_NAME}" savestate | |
} | |
vmStatus() { | |
local RUNNING_VMS=$(VBoxManage list runningvms) | |
if [[ $? != 0 ]]; then | |
echo "Command failed." | |
elif [[ $RUNNING_VMS ]]; then | |
echo "Running VirtualBox VMs:" | |
echo $RUNNING_VMS | |
else | |
echo "No VirtualBox VMs are running." | |
fi | |
} | |
vmConnect() { | |
ssh -p 2222 [email protected] | |
} | |
case "$1" in | |
start) | |
vmStart;; | |
stop) | |
vmStop;; | |
status) | |
vmStatus;; | |
connect) | |
vmConnect;; | |
*) | |
echo $"Usage: $0 {start|stop|status|connect}" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment