Sample Header Ad - 728x90

Run PSQL command from bash script

2 votes
1 answer
10713 views
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  & \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: * https://stackoverflow.com/questions/35347368/unable-to-run-psql-command-from-within-a-bash-script - about running SQL not a PSQL command * https://stackoverflow.com/questions/54619776/cannot-get-psql-command-to-run-in-bash-script - seems to be about running a .sql script But they're not what I'm after.
Asked by baxx (326 rep)
Nov 21, 2022, 12:01 PM
Last activity: Nov 21, 2022, 01:14 PM