Start and connect to your VirtualBox VM with a simple script

The way I like to develop is to create specific virtual machines for my web development.

The chore is to start the machine, mount the file system and then open up your IDE. All a nuisance that takes time. So, I’ve taken to writing a simple Bash script that will do the grunt work for you. All you have to do is put in your settings, save it and run it!

This will mount the VM’s web folder onto your file system and let you know it’s connected. All you need to do is then start your IDE of choice!

 #!/bin/bash
WEBIP='10.0.0.211'
VM='Web Development'
VMUSER='webadmin'
VMMOUNT='/var/www'
MOUNTPOINT='/home/user/mnt/sshmnt/'

VBoxHeadless -s "$VM" & #This starts the VM you've chosen
while :; do echo "Connecting..."
  if nc -zv -w5 $WEBIP 22 <<< '' &> /dev/null #Tests the connection is available
  then
    if sshfs $VMUSER@$WEBIP:$VMMOUNT $MOUNTPOINT
      #We have to test because even though the connection is available, the SSH
      #Server might not be ready
      then
        echo 'Connected!'
        exit
      fi
    else
# echo "Can't connect" #Use this to debug is nc is working
  fi
done 

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
, PHPlist