#! /bin/bash

[[ -z "$1" ]] && echo 'usage: masters <xtable|xstore|...>' && exit 1
PSQL_DUMP="/tmp/psql_error"
list "$1" | while read CONNINFO; do
    DB_NAME=`expr "$CONNINFO" : '.*dbname=\([a-zA-Z0-9_\-]*\)'`
    MASTER_HOST=`psql -c '\echo :HOST' "$CONNINFO connect_timeout=1" 2>"$PSQL_DUMP" || echo "failed, see $PSQL_DUMP for details"`
    echo "$DB_NAME: $MASTER_HOST"
done
