#!/bin/bash
if [ ! -f "$1" ] ; then
  echo "error: must specify active rooms file"
  exit 1
fi

NUM=0
while read FOO; do
  if ! echo $FOO | grep -q ^#; then
    HOST="`echo $FOO | cut -d\| -f3`"
    MAC="`echo $FOO | cut -d\| -f1 | tr '[A-Z]' '[a-z]'`"
    IP="`echo $FOO | cut -d\| -f2`"
    if ! echo $HOST | egrep -q "server"; then
      if grep -q "^$HOST\$" "$1" ; then
        >&2 echo found host $HOST mac $MAC ip $IP num $NUM
        echo "$HOST|$MAC|$IP|$NUM"
        NUM=$((NUM+1))
      fi
    elif echo $HOST | grep -q server; then
      >&2 echo found server at ip $IP
      echo $IP > SERVERIP
    fi
  fi
done < MASTER_LIST > HOSTS
