#!/bin/bash # Quick way to login (SSH) to nodes created with virtnet # Assumes that nodes are named, node1, node2, ..., node10, node11, ... # and that port forwarding is enabled on ports 2201, 2202, ..., 2210 etc # These assumed values are the default when using vn-createtopology. For # example, if you have previously run: # vn-createtopology 2 # then you will have two nodes, node1 and node2, and with SSH port # forwarding on 2201 and 2202. Then this script should work. # # Example usage: # vn-ssh 1 # will start (if not already running) node1 and then SSH into it. # Path for virtnet directory on host, e.g. /home/user/svn/virtnet/ virtnethostpath="`dirname $BASH_SOURCE`/../../" # Check if node exists VBoxManage list vms | grep "\"node$1\"" > /dev/null isvm=$? if [ "${isvm}" = "1" ]; then echo "vn: node$1 does not exist. Use 'VBoxManage list vms' to see available nodes." echo "vn: ERROR. Exiting." exit 1 else # Check if node is running VBoxManage list runningvms | grep "\"node$1\"" > /dev/null isrunning=$? # If not running, then start it if [ "${isrunning}" = "1" ]; then echo "vn: Starting node$1 ..." VBoxManage startvm --type headless node$1 fi fi # node1 => port 2201, node2 => port 2202, ..., node10 => port 2210, etc if [ $1 -lt 10 ]; then port=220$1 else port=22$1 fi # SSH into the node, without performing checking of keys echo "vn: Logging into node$1 with SSH ..." ssh -o "StrictHostKeyChecking no" -l network -p ${port} -i ${virtnethostpath}/data/defaults/home/network/.ssh/id_rsa localhost