Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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
add comment

2 Answers

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
add comment
rpm -Uvh postgresql91-*.rpm &> install.log 

This should send all output to your log file.

share|improve this answer
add 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.