Skip to main content
final command
Source Link
Poutrathor
  • 141
  • 1
  • 6
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 :

  1. pg_dump goes to stdout
  2. 2>&1 dumps error stream to stdout
  3. | pipes the stdout & errout
  4. to tee -a, which will keep the pipe content and forward it (with append option at least for first forward) to several commands
  5. >"${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.
  6. >(psql -p 5432 -U postgres db-project >>"${LOGFILE}") THEN my first COPY as a psql command (with wrapping parenthesis for a command)
  7. >>"${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.
  8. >(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}") THEN the second psql command with a second appending of stdout to the logfile.
  9. 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.

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 :

  1. pg_dump goes to stdout
  2. 2>&1 dumps error stream to stdout
  3. | pipes the stdout & errout
  4. to tee -a, which will keep the pipe content and forward it (with append option at least for first forward) to several commands
  5. >"${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.
  6. >(psql -p 5432 -U postgres db-project >>"${LOGFILE}") THEN my first COPY as a psql command (with wrapping parenthesis for a command)
  7. >>"${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.
  8. >(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}") THEN the second psql command with a second appending of stdout to the logfile.
  9. 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.

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 :

  1. pg_dump goes to stdout
  2. 2>&1 dumps error stream to stdout
  3. | pipes the stdout & errout
  4. to tee -a, which will keep the pipe content and forward it (with append option at least for first forward) to several commands
  5. >"${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.
  6. >(psql -p 5432 -U postgres db-project >>"${LOGFILE}") THEN my first COPY as a psql command (with wrapping parenthesis for a command)
  7. >>"${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.
  8. >(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}") THEN the second psql command with a second appending of stdout to the logfile.
  9. 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.

Source Link
Poutrathor
  • 141
  • 1
  • 6

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 :

  1. pg_dump goes to stdout
  2. 2>&1 dumps error stream to stdout
  3. | pipes the stdout & errout
  4. to tee -a, which will keep the pipe content and forward it (with append option at least for first forward) to several commands
  5. >"${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.
  6. >(psql -p 5432 -U postgres db-project >>"${LOGFILE}") THEN my first COPY as a psql command (with wrapping parenthesis for a command)
  7. >>"${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.
  8. >(psql -p 5432 -U postgres db-gp-projet >>"${LOGFILE}") THEN the second psql command with a second appending of stdout to the logfile.
  9. 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.