[baylisa] Re: wtf: hostid gives '0' as a hostid

David Alban extasia at extasia.org
Tue Feb 19 12:05:28 PST 2008


On Feb 16, 2008 7:11 PM, Ray Wong <rayw at rayw.net> wrote:
> Indeed, fairly safe to say that any uniqueness is valid only insofar as the
> local site policy enforces it.  I've used SSH host keys to check uniqueness
> at some sites, but I've also shared host keys amongst interchangable hosts
> to smooth failover scenarios (clearly not at the same site).
>
> I suppose since we're likely all perl hax0Rz it could make sense to make
> a hash of hash of hash index using several items and try to remember never
> to violate uniqueness on all of them at once. :)

i really liked the idea of using ssh host keys, but when i used
ssh-keygen to look at the host key fingerprints of several of the
candidate machines i found some of them sharing the same host key.

so here's a working solution for me.  it's not a universal solution.
i have the advantage of having all linux machines in my problem space.
 it does an md5sum on the combined output of 'uname -a', the lines in
ifconfig output that contain either an IP or mac address (i'm not
bothering to filter out 127.0.0.1, although someone else could if they
wanted to), and only the values in free output indicating total memory
and swap on the machine.

    #/bin/bash

    export PATH=/sbin:/bin:/usr/sbin:/usr/bin

    hostname="$( hostname )"

    problems_encountered=0

    uname_output="$( uname -a )"
    if [[ $? != 0 ]]; then
      echo 1>&2 "[$hostname] uname failed"
      problems_encountered=$(( $problems_encountered + 1 ))
    elif ! echo "$uname_output" | grep '^Linux' >/dev/null ; then
      echo 1>&2 "[$hostname] os type failed (not linux)"
      problems_encountered=$(( $problems_encountered + 1 ))
    fi

    ifconfig_output="$( ifconfig )"
    if [[ $? != 0 ]] ; then
      echo 1>&2 "[$hostname] ifconfig failed"
      problems_encountered=$(( $problems_encountered + 1 ))
    fi

    free_output="$( free )"
    if [[ $? != 0 ]] ; then
      echo 1>&2 "[$hostname] free failed"
      problems_encountered=$(( $problems_encountered + 1 ))
    fi

    { echo "$uname_output"
      echo "$ifconfig_output" | egrep '(inet|HWaddr) '
      echo "$free_output" | awk '{ print $1,$2 }' | egrep '^(Mem|Swap):'
    } | md5sum | awk '{ print $1 }'

    exit $problems_encountered

output is an md5sum.

output of the echo block which is being summed would look something like:

    Linux some.host.name 2.6.9-55.0.2.ELsmp #1 SMP Tue Jun 12 17:59:08
EDT 2007 i686 i686 i386 GNU/Linux
    eth0      Link encap:Ethernet  HWaddr 01:23:45:67:89:AB
              inet addr:10.11.12.13  Bcast:10.11.12.255  Mask:255.255.255.0
              inet addr:127.0.0.1  Mask:255.0.0.0
    Mem: 4152916
    Swap: 2096472

for my solution, i only need the unique id to be good for about an
hour.  so if a host "has work done on it" and some of the attributes
change, that's ok with me.  i don't need data any older than an hour.

-- 
Live in a world of your own, but always welcome visitors.



More information about the Baylisa mailing list