Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Redirect stderr as well.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" &> vacuum.log
share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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