4

Here is my script :-

sudo mate-terminal --geometry=50x10 -x sh -c "dd if=/dev/sda of=/dev/sdb status=progress 2>&1 | tee log.txt | md5sum > hash.txt | sha1sum > hash1.txt"

I've seen people giving this suggestion all the time; putting 2>&1. But this will only display the progress in the log.txt file and the terminal will display nothing. Here's a picture of what the progress look like on the log.txt file.

logfile

If I remove 2>&1 and just go with

command | tee log.txt

Only the terminal will show the progress and nothing will display in the log.txt file

I've also tried:-

(command 2>&1) | log.txt

command 2> | log.txt

and many more I can't recall. So can someone help me?

Zanna
  • 69,223
  • 56
  • 216
  • 327
Najmi
  • 63
  • 1
  • 7

2 Answers2

3

The progress is output to STDERR rather than STDOUT. You could get something like what you want by doing tail -f on the file being written to like this:

mate-terminal --geometry=50x10 -x sh -c 'tail -f log.txt'
sudo dd if=/dev/sda of=/dev/sdb status=progress 2> log.txt"

tail -f log.txt will print everything being written to log.txt to the new smaller terminal and run as a background process so you can issue more commands while it runs.
2> sends STDERR stream to log.txt. If there is any output on STDOUT it will display in the terminal from which the command or script is run.

Zanna
  • 69,223
  • 56
  • 216
  • 327
  • Hi @Zanna, I remember you from my older question :) This doesn't work for me. If you can refer to this picture http://pictub.club/image/HLUp8 I want to redirect the progress to the blue terminal. The black terminal I use to execute my tools. Now the progress is displayed on the black terminal and also it also logs it on the .txt file but I wanted it so that it display on the blue terminal. Oh and I've edited your script a bit changing from "sudo bash -c" to "sudo mate-terminal --geometry=50x10 -x sh -c" – Najmi Nov 08 '16 at 05:13
  • @Najmi ah I see :) how this could sort-of work then, is if you send the `tail -f` command to the other terminal (where you want to see the progress) - I'll see if I can fix it. But my answer is just an imperfect workaround anyway, now @muru has given you the real answer and taught us both how to do it correctly. – Zanna Nov 08 '16 at 06:29
  • I'm reading on dc3dd right now. Seems promising. Will write back if it works – Najmi Nov 08 '16 at 08:10
  • @Najmi edited, hope it is useful. I still think muru's answer is better though :) – Zanna Nov 08 '16 at 08:30
2

Redirect both stderr and stdout with |& in bash:

sudo mate-terminal --geometry=50x10 -x bash -c "dd if=/dev/sda of=/dev/sdb status=progress |& tee log.txt"
muru
  • 193,181
  • 53
  • 473
  • 722
  • it worksss ! But.... when I add | md5sum > hash.txt | sha1.txt > hash1.txt, it doesn't display the progress on the terminal anymore. Got any idea ? – Najmi Nov 08 '16 at 06:22
  • What exactly is `| md5sum > hash.txt | sha1.txt >hash1.txt` supposed to be doing? – muru Nov 08 '16 at 06:28
  • to log the md5 and sha1 hash value. I'm developing a forensic tools and I need the hash value is to verify that the cloned drive is the same as the drive being clone – Najmi Nov 08 '16 at 08:07
  • Hash values of what, exactly? What do you imagine is happening in that pipeline? – muru Nov 08 '16 at 08:09