Skip to content

Instantly share code, notes, and snippets.

@ruskotron
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruskotron/fbf04bac53d86d84498c to your computer and use it in GitHub Desktop.
Save ruskotron/fbf04bac53d86d84498c to your computer and use it in GitHub Desktop.
Start a Vagrant VM without having to use "vagrant up" (which can potentially destroy your VM if it prior "vagrant halt" didn't work properly)
#!/usr/bin/bash
#
VM_NAME=$1
SSH_PORT=$(VBoxManage showvminfo ${VM_NAME} --machinereadable | awk -F, '/^Forwarding\([0-9]+\)="/ && $NF == "22\"" { print $(NF-2) ; exit}')
echo "SSH PORT: $SSH_PORT"
VBoxManage.exe list runningvms | grep -q "^\"$VM_NAME\" " || (
VBoxManage startvm ${VM_NAME} --type headless
)
# add ssh key (from "ssh-keygen") to ~root/.ssh/authorized_keys to get rid of this password prompt
ssh root@localhost -p ${SSH_PORT} <<-END
ls -d /vagrant/* > /dev/null || mount.vboxsf vagrant /vagrant
ls -d /smbmount/* > /dev/null || mount.vboxsf smbmount /smbmount
END
# add ssh key (from "ssh-keygen") to ~vagrant/.ssh/authorized_keys to get rid of this password prompt
ssh vagrant@localhost -p ${SSH_PORT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment