dd output redirection
hello folks,
I am trying to write a shell script in which I use the "dd" command to perform some measurements on a hard disk , I want to redirect the output message of the "dd" command to a file as the following: Code:
(dd if=/dev/zero of=/dev/sda bs=1M count=128) >> myFile.log that did not work, nothing is written in the file. any suggestions ? :scratch: |
The output from dd goes to stderr so change to (dd if=/dev/zero of=/dev/sda bs=1M count=128) 2>> myFile.log
The ( ... ) used that way does not achieve anything so it could be, more simply dd if=/dev/zero of=/dev/sda bs=1M count=128 2>> myFile.log |
The messages output by dd are going to standard error (STDERR) rather than standard output (STDOUT). When you do ">" or ">>" you're redirecting STDOUT. You need to redirect STDERR instead.
Code:
dd if=/dev/zero of=/dev/sda bs=1M count=128 2>> myFile.log Code:
dd if=/dev/zero of=/dev/sda bs=1M count=128 >> myFile.log 2>&1 Also note that when doing this it is important to define STDOUT redirect BEFORE doing the 2>&1. If you did it the opposite way it would redirect STDERR to wherever STDOUT was before STDOUT was redirected (typically the display). |
thank you very much :D
|
Greetingz!
I'm curious about something. Why the decision to use 'dd' rather than the output of 'fdisk -l /dev/sda'? |
All times are GMT -5. The time now is 12:20 AM. |