Warning: Trying to access array offset on value of type bool in /home/www/blog/wp-content/themes/catch-box/functions.php on line 1079

VMWare Scripting

We are using Oracle Enterprise Linux 64bit installations in VMWare Fusion (32GB MacPros). In principal there are two possibilities to access running processes vmrun and normal IP-based protocols.

Here are two bash functions to support scripting:

Script to select one of the running VMWare boxes

SelectVMWare() {

	IFS='
	'
	listOfVMWares=(`vmrun list`)

	echo -e "\n\n Please select Client to Install:"

	for((i=1;i<${#listOfVMWares[*]};i++)) do
		echo -e  "\t\t" $i "  " ${listOfVMWares[$i]}
	done

	read CLIENT_SELECTION

	CLIENT_VMX=${listOfVMWares[$CLIENT_SELECTION]}
}

If you want to access the boxes by e.g. SSH you will need the IP-number. This is possible by using the MAC address parsed from the given VMX-file, fping (it is no default on OSX) and arp.

Script to get the IP address (runs on Snow Leopard)


GetIP() {
	fping -c 1 -g -q 176.16.8.0/24 2> /dev/null;  # pings all of subnet

	# get the MAC address
	MAC_ADDRESS=`grep "ethernet0.generatedAddress " $1 | sed 's/.*= "00:\(.*\)"/\1/'`

	# set the field separator to : and create an array
	IFS=":"
	temp=( $MAC_ADDRESS )

	# iterate through the array and delete the leading zeros
	for i in {0..4}
	do
	   characters=`echo ${temp[i]} |wc -m`
	   if [ $characters -gt 2 ]; then
		  temp[i]="${temp[i]/#0/ }"
	   fi
	done

	# change IFS back and create corrected MAC address
	IFS=","

	MAC_TEMP=${temp[0]}:${temp[1]}:${temp[2]}:${temp[3]}:${temp[4]}
	MAC_ADDRESS=`echo $MAC_TEMP | sed -e 's/ //g'`
	MAC_MATCH=0:$MAC_ADDRESS

	#echo $MAC_MATCH
	#echo $MAC_ADDRESS

	# convert MAC address
	IP_ADDRESS=`arp -an |grep $MAC_ADDRESS |sed "s/.*? (\(.*\)) at $MAC_MATCH on vmnet1 ifscope \[ethernet\]/\1/"`

	#echo found IP: $IP_ADDRESS Is this OK?
	#read -n1
}