LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Script output for DD not being written to file (http://www.linuxquestions.org/questions/linux-server-73/script-output-for-dd-not-being-written-to-file-815791/)

mhouston100 06-22-2010 08:27 PM

Script output for DD not being written to file
 
Hi guys, I'm having some real dramas with the output for a dd command being called from a script. Basically i'm trying to write the whole output from the script to a log file. It all seems to be working fine except the dd command.

So i'm calling the script with:

Code:

sh ./script.sh > Logfile.log
Everything gets written to the logfile correctly except the dd commands:

dd bs=2M if=/dev/sda | gzip --fast > /backup/ProntoLVM1_$(date +%d-%m-%Y).bak.gz

The output of this (time, amount of records etc) all still gets printed to the console. I've tried redirecting it with >>, with 2> with 2>&1 etc but it always still gets written to the screen and not the file.

Is there something I'm missing here? Some of those seems to write the actual dd data being copied to the file instead of the output.

Is the correct syntax for the 2>&1 redirect:

Code:

command 2>&1 backuplog.log
Thanks in advance guys
-Matt

EDIT :: Sorry, on RHEL 5.5 server.

smoker 06-22-2010 10:27 PM

I would write it as :
Code:

dd bs=2M if=/dev/sda | gzip --fast > /backup/ProntoLVM1_$(date +%d-%m-%Y).bak.gz >>backuplog.log 2>&1
http://tldp.org/LDP/abs/html/io-redirection.html

konsolebox 06-23-2010 12:24 AM

You can redirect the script in general:
Code:

exec 4>&1  # open stdout dup 4

command1 >&4
command2 >output.txt 2>&4
command3 2>&4 | command4 2>&4 > somefile.gz

exec 4>&-  # close

And not sure if this will also work but perhaps you can also just use brackets:
Code:

{
    command1 >&4
    command2 >output.txt 2>&4
    command3 2>&4 | command4 2>&4 > somefile.gz
} 4>&1



All times are GMT -5. The time now is 02:11 PM.