#! /bin/sh
 
#echo "Set to LocalHostName"
PREF=/Library/Preferences/SystemConfiguration/preferences.plist
HOSTS=/etc/hosts
IP=`ifconfig en0 |grep inet |grep netmask |awk -F" " '{print $2}'`
HOSTNAME=`grep $IP $HOSTS |awk -F" " '{print $2}'`

/usr/sbin/scutil --set ComputerName ${HOSTNAME}
/usr/sbin/scutil --set LocalHostName ${HOSTNAME}
/bin/hostname ${HOSTNAME}
