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.

link|improve this question

68% accept rate
feedback

1 Answer

up vote 2 down vote accepted

Redirect stderr as well.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" &> vacuum.log
link|improve this answer
@Ignacio: Thanks, that's working perfectly as expected. Actually, I'm not a Linux expert, for me to understand this better, & is the stderr and > is standard output? – Gnanam Sep 1 '10 at 10:13
> is stdout, 2> is stderr, &> is both. – Ignacio Vazquez-Abrams Sep 1 '10 at 10:37
@Ignacio: Thanks again. Can you share with me some useful resource about Linux redirection operators? – Gnanam Sep 1 '10 at 10:52
@Gnanam: Also, the Bash Manual section on Redirections and Greg Wooledge's BashGuide section on Redirection. – Dennis Williamson Sep 1 '10 at 15:08
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.