#!/bin/bash
#
# test_pgsql_variables
#
###########################################
#
if [[ ! -f /etc/uls/pgsql_variables.conf ]]
 then
  exit 0
fi
#
. `dirname $0`/uls_header "$@"
#
if [[ -f /etc/uls/pgsql.conf ]]
 then
  . /etc/uls/pgsql.conf
else
  echo "/etc/uls/pgsql.conf not found."
  exit 0
fi
#
pgsql()
{ /usr/bin/psql -A -F ';' -q -c "$1"
}
#
( L=`pgsql '\encoding'`
  echo "L;;;;;;$L;"
  echo "D;$DT;${ULSNAME:-${ULSHOSTNAME:-`hostname`}};PostgreSQL;"
  ( pgsql "show ALL"
    echo "MAGIC7348576"
    grep -v '^ *#' /etc/uls/pgsql_variables.conf
  ) | sed 's/^ *//' | awk -F ';' '
BEGIN { C = 0 }
/MAGIC7348576/ { C++
                 FS = " "
               }
NF >= 2 { if( C == 1 )
          { for( a in w )
            { if( a ~ "^"$2"$" )
              { if( w[a] ~ "^[-+]?[0-9]+$" )
                { print "V;;;;variables:" $1 ";" a ";" w[a] ";#"
                  print "A;;;;variables:" $1 ";" a ";\"" d[a] "\";#"
                }
                else
                { print "V;;;;variables:" $1 ";" a ";" w[a] "; "
                  print "A;;;;variables:" $1 ";" a ";\"" d[a] "\"; "
                }
              }
            }
          }
          else if( $2 != "" )
          { w[$1] = $2
            gsub("\"", "\\\"", $3)
            d[$1] = $3
          }
        }
') | send_test_tab
