.local hostname available as an environmental variable?

Hola -

I've got a script for logon which populates a database with some info when a user logs on so that we can tell how many public terminals are in use & show users which ones are free. However, the machines are DHCPed and so using $HOSTNAME gives me an unstable name for them since of course the leases may change.

Is it possible to determine the .local hostname programatically and put it into an environmental variable I can call? We don't have too terribly many of these so that if I had to set an variable for each one by hand & call that I could do so, but of course, I'm hoping the .local name is available to me somehow.

Many thanks for any help or pointers here, greatly appreciated.

I take it using /etc/hostname is out of the question? You could cheat by creating a file in /etc (say myname) which then contains a unique identifier for each machine. Then the script can read the file in some manner similar to:

MYNAME=$(</etc/myname)

Another way would be to use the MAC address of the machine which will be unique. As you are using a database anyway the MAC address could be in there with an associated unique name. Accessing the MAC address depends on the system - on Linux I can find mine by using the ifconfig command. With Solaris you search for the local machine in the arp table. I don't know how MACOS X does it.

Alternatively could your DHCP server administrator be persuaded to reserve each IP address for each MAC address, making the IP address and therefore hostname constant?

Andrew

Thanks Andrew, as it turns out there is a new to me command scutil taht I can use to grab the localhostname -- scutil --get LocalHostName -- easy enough to pop into the script.

Many thanks for your thoughts & assistance here!

from the DHCP server side
i use my DHCP logs starting with a simple grep;

 awk '{print $11,$10,$12}' /var/log/system.log | grep iP

the pipe to grep is for sorting by iP or iPhone/iPod you could use "hostname" or anything you want to search on. then you can off that to temp list , which can be processed again and again etc,....

or you can pull specific info from your DHCP.leases file mac address hostname etc,..