Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Created December 11, 2014 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianwebber/d3e4ad21d086ebde8a5b to your computer and use it in GitHub Desktop.
Save sebastianwebber/d3e4ad21d086ebde8a5b to your computer and use it in GitHub Desktop.
Generates pgauth's file
#!/bin/bash
export AUTH_FILE=/etc/pgbouncer/pgbouncer.auth
TMPFILE=$( mktemp )
trap 'rm -f "$TMPFILE"' EXIT
psql -Upostgres -p 9876 -qAtX -c 'SELECT $$"$$ || replace( usename, $$"$$, $$""$$) || $$" "$$ || replace( passwd, $$"$$, $$""$$ ) || $$"$$ from pg_shadow where passwd is not null order by 1' > "$TMPFILE"
if [[ ! -s "$TMPFILE" ]]
then
exit
fi
if diff -q "$AUTH_FILE" "$TMPFILE" &>/dev/null
then
exit
fi
cat "$TMPFILE" > "$AUTH_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment