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
  • 72,312
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
  • 72,312
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
  • 207,228