Hey, I found the answer to this problem, so I'm posting the relevant code here:
varNewname=(Put the newname here if)
esxcfg-advcfg -s $ /Misc/HostName
perl -pi -e "s/^HOSTNAME=.*/HOSTNAME=$varNewname/g" /etc/sysconfig/network
Hope this helps someone else 