2

I would like to know how to run \du within a script, and output that to a file.

Something like the following:

# some_script.sh

psql <database connection> & \du > output_of_du.txt

I can find information about running .sql files via psql, but I can't find information about running psql commands themselves.

I found the following whilst searching:

But they're not what I'm after.

baxx
  • 326
  • 2
  • 7
  • 18

1 Answers1

4

You can use the -c flag and combine it with -L to gather the output:

psql <database connection> -c \du -L output_of_du.txt

See psql-tip number 1 (https://psql-tips.org/psql_tips_all.html#tip001) and psql-tip number 26 (https://psql-tips.org/psql_tips_all.html#tip026)

Arkhena
  • 1,610
  • 10
  • 15