Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 06-22-2010, 08:27 PM   #1
Registered: Jun 2010
Posts: 32

Rep: Reputation: 16
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:

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:

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

EDIT :: Sorry, on RHEL 5.5 server.

Last edited by mhouston100; 06-22-2010 at 08:27 PM. Reason: Add info
Old 06-22-2010, 10:27 PM   #2
Senior Member
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
I would write it as :
dd bs=2M if=/dev/sda | gzip --fast > /backup/ProntoLVM1_$(date +%d-%m-%Y).bak.gz >>backuplog.log 2>&1

Last edited by smoker; 06-22-2010 at 10:43 PM.
Old 06-23-2010, 12:24 AM   #3
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
You can redirect the script in general:
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:
    command1 >&4
    command2 >output.txt 2>&4
    command3 2>&4 | command4 2>&4 > somefile.gz
} 4>&1


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script output can't be redirected to a file nasridine Programming 7 02-19-2010 12:13 AM
Unable to redirect script output to a file alien12 Linux - Newbie 4 08-25-2009 03:36 AM
Expect script - No output to file pandersson61 Programming 4 05-23-2007 05:18 AM
cpu, mem, ps output to file script beeblequix Linux - Enterprise 3 09-08-2006 03:08 PM
shell script output to file drum2jc Linux - Software 1 05-30-2006 06:54 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration