1
0

postgres_listdb 486 B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. [ $# -lt 1 ] && exit 6
  3. PSQL=`which psql`
  4. USE_SU=${1}
  5. HOST=${2}
  6. USER=${3}
  7. PG_OPTS1=
  8. PG_OPTS2=
  9. [ -n "${USER}" ] && PG_OPTS1="-U ${USER}"
  10. [ -n "${HOST}" ] && PG_OPTS2="-h ${HOST}"
  11. if [ "${USE_SU}" == "no" ]; then
  12. $PSQL -l ${PG_OPTS1} ${PG_OPTS2} -t -x | grep Name | awk '{ print $3 }' | grep -v template
  13. ret=$?
  14. else
  15. su postgres -c "$PSQL -l ${PG_OPTS1} ${PG_OPTS2} -t -x | grep Name | awk '{ print \$3 }' | grep -v template"
  16. ret=$?
  17. fi
  18. exit ${ret}