Howdy...
The below scripts will let you ssh or connect to other networked services in your virtual machines from the mac os command line easily, without having to lookup or remember IP addresses the VM gets dynamically. This is handy if you're like me and use bridged wireless networking, and routinely connect to different wireless networks. Instead of going to your VM, finding your ip address, going back to os x, and then inputting that ip address every time you get a new lease or switch networks, you can simply do one of the following:
Code:
[B]sshvm[/B] [ EXTRA ARGS TO SSH ]
ssh [ EXTRA ARGS TO SSH ] `[B]vm[/B]`
ftp `[B]vm[/B]`
telnet `[B]vm[/B]`
... etc ...
vm calls the necessary networking magic to determine what your VM's ip address is from os x. Note that sshvm merely calls ssh with the result of the vm command.
Before you run the script you will want to change the MAC_ADDR line in the vm script, or else it won't work. On linux you can determine this from /sbin/ifconfig output.
The files are included inline below - if you need this you will probably find the format & install procedure self-explanatory, but, briefly, copy the files somewhere in your $PATH, chmod +x and you should be good to go.
Here's hoping someone besides me finds this useful.
Cheers!
sshvm:
Code:
#!/bin/sh
vm=`vm`
[ ! -z $vm ] && ssh $* $vm
vm:
Code:
#!/bin/sh
# set this to whatever arp address parallels gives the vm in question
MAC_ADDR="0:e8:ee:2a:56:e8"
# that's it!
# find where the VM is by ARP address (which is permanent it seems)
arpout=`arp -n -a | grep -i "$MAC_ADDR"`
# if the vm isn't yet in the arp table, ping everyone to try to get it...
if [ -z "$arpout" ] ; then
#find broadcast on default interface
interface=`route -n get default | grep interface | sed 's/^.*: *//'`
broadcast=`ifconfig en1 | grep broadcast | sed 's/^.*broadcast *//'`
#get IPs for possible hosts
hosts=`ping -t 1 $broadcast | grep "^[0-9]* *bytes *from *" | \
sed 's/^[0-9]* *bytes *from *//' | sed 's/:.*$//'`
#get mac addresses for each of these hosts
for host in $hosts ; do
ping -c 1 -t 1 $host >/dev/null 2>&1
done
arpout=`arp -n -a | grep -i "$MAC_ADDR"`
fi
# get IP address from arp output line
ip=`echo $arpout | sed 's/^\? *[\(]//' | sed 's/[\)] at .*$//'`
# if we got something, print it and exit
if [ ! -z "$ip" ] ; then
echo $ip
exit 0
else
echo "can't determine VM's address - are you sure it is running and network configured?" >&2
exit 1
fi