pg_dump -a -t table-country -p 5432 -U usr db-maint2 2>&1 | tee -a >"${LOGFILE}" >(psql -p 5432 -U postgres db-project >>"${LOGFILE}") >(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}") Why ?
Because, from left to right :
pg_dumpgoes to stdout2>&1dumps error stream to stdout|pipes the stdout & errout- to
tee -a, which will keep the pipe content and forward it (with append option at least for first forward) to several commands >"${LOGFILE}"FIRST I want to log the pg_dump stdout or errout. Note the syntax for this : no()around the file name. I use a variable in my script.>(psql -p 5432 -U postgres db-project >>"${LOGFILE}")THEN my first COPY as a psql command (with wrapping parenthesis for a command)>>"${LOGFILE}"inside previous line, I use this to append (double>) to my file the stdout of psql (I don't get the errout here, I could have.>(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}")THEN the second psql command with a second appending of stdout to the logfile.- No output to console, everything is kept by tee, it seems (don't know why to be honest).
Hope it helps some people to understand tee and pipe use cases.
Edit : my final command is
pg_dump -a -t table-country -p 5432 -U usr db-maint2 2>&1 | tee -a > /dev/null >(psql -p 5432 -U postgres db-project >>"${LOGFILE}") >(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}") It drops the standard output rather than polluting the logfile. It would be best to keep the error stream into the logfile though with
pg_dump -a -t table-country -p 5432 -U usr db-maint2 2>"${LOGFILE}" | tee -a > /dev/null >(psql -p 5432 -U postgres db-project >>"${LOGFILE}") >(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}") but it's not tested yet.