Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bash script to install postgresql
part of the script contains this command

rpm -Uvh postgresql91-*.rpm

i need to direct ALL the output generated by this rpm command into a log file FROM within my bash script
I have tried this

rpm -Uvh postgresql91-*.rpm
>> install.log

however this doesnt stop the following output appearing within my puTTy session
package pgdg-redhat91-9.1-5.noarch is already installed
package postgresql91-libs-9.1.9-1PGDG.rhel6.x86_64 is already installed
package postgresql91-9.1.9-1PGDG.rhel6.x86_64 is already installed
package postgresql91-server-9.1.9-1PGDG.rhel6.x86_64 is already installed

how do i redirect all output into my .log file?

share|improve this question
so you run command like rpm -Uvh postgresql91-*.rpm >> install.log in one line? – mirkobrankovic Jul 3 '13 at 11:53
Running that in one line should put all output to install.log – Bolli Jul 3 '13 at 11:56
yes its all on a single line. do i need to add 2>&1 at the end of that single line? – Hector Jul 3 '13 at 12:26
@Bolli, that command only redirects stdout to the file, stderr is still output in that case. The OP wants &>, as in my answer below. – nerdwaller Jul 3 '13 at 12:44
@nerdwaller Thanks I didnt know :) – Bolli Jul 3 '13 at 16:03
up vote 2 down vote accepted

You're only redirecting stout to the file. instead you want to redirect stderr and stdout.

You should just need to do

 command &> file.txt

You may want to read a bit more on Bash Redirection

share|improve this answer
quality answer... thanks for the link as well – Hector Jul 3 '13 at 14:16
rpm -Uvh postgresql91-*.rpm &> install.log 

This should send all output to your log file.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .