LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 06-22-2010, 08:27 PM   #1
mhouston100
Member
 
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:

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.

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

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

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

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


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 12:03 AM.

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