Linux – How to redirect console output of command to a logfile

bashcommand-line-interfacelinuxpostgresql

My OS is RHEL5.

I want to direct the console output produced by the following database command to a log/file.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE"

I've tried out the following commands and is not working as expected. But it is printing output to the terminal console instead.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" > vacuum.log
psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" | tee vacuum.log

Here, in this case, is not the output produced by this command a standard input/output/error?

NOTE: psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results.

Best Answer

Redirect stderr as well.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" &> vacuum.log