[Gllug] $HOSTNAME
Hari Sekhon
hpsekhon at googlemail.com
Tue Sep 8 16:41:08 UTC 2009
Hari Sekhon wrote:
> John G Walker wrote:
>> On Tue, 8 Sep 2009 16:32:50 +0100 Stephen Nelson-Smith
>> <sanelson at gmail.com> wrote:
>>
>>
>>> It's probably safer to use $(hostname -s)
>>>
>>
>> Safer in what way? I just use the name as a string
> Technically $HOSTNAME can be blank (but usually isn't) but hostname -s
> seems more likely to return something as it uses the system's
> gethostname function call which pulls the hostname from sysfs and one
> would think it's safer but I just tested it and it's not really any
> safer, you could blank that out too for example or change it to the
> name of another machine on the network and hostname -s will happily
> return that or an unknown host error if it's blank or not resolvable.
>
> Some elementary shell scripting will allow you to test for any of this
> though... and if you're writing anything without such tests then your
> code simply isn't robust, and shell scripting usually garners
> criticism from people who aren't very adept at writing it for this
> very reason. Defensive programming should be employed regardless.
err, quick self correction, it's not sysfs but /proc/sys that that
function call is pulling the hostname from... got sysfs on the brain...
-h
--
Hari Sekhon
http://www.linkedin.com/in/harisekhon
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list