A
A
Aryeh Leonid R.2021-10-14 14:22:49
linux
Aryeh Leonid R., 2021-10-14 14:22:49

How to run a command in Linux in the background saving console output to a file using tee?

I run the command

dd if=/dev/zero of=/tmp/zerofile  bs=100M count=5 &

a few seconds and the answer is displayed in the console
5+0 records in
5+0 records out
524288000 bytes (524 MB, 500 MiB) copied, 2.04649 s, 256 MB/s

[1]+ Done dd if=/dev/zero of=/tmp/zerofile bs=100M count =5

I want to see this output in the console and save it to a file. I run the command:
dd if=/dev/zero of=/tmp/zerofile  bs=100M count=5 | tee ku.log &

a few seconds and the answer is displayed in the console
5+0 records in
5+0 records out
524288000 bytes (524 MB, 500 MiB) copied, 2.04649 s, 256 MB/s

[1]+ Done dd if=/dev/zero of=/tmp/zerofile bs=100M count =5 | tee-ku.log

However, the ku.log file is empty!
So - how to achieve drying of the log in such a situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2021-10-14
@aryeh

The program ddoutputs the report not to stdout, but to stderr. So you need to first redirect stderr to stdout, and then pass it to tee:

# башизм
dd if=/dev/zero of=/tmp/zerofile  bs=100M count=5 |& tee ku.log &
# должно работать везде
dd if=/dev/zero of=/tmp/zerofile  bs=100M count=5 2>&1 | tee ku.log &

R
Ronald McDonald, 2021-10-14
@Zoominger

(dd if=/dev/zero of=/tmp/zerofile  bs=100M count=5 > ku.log) &

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question