Linux Pipe viewer, how to split the pipe

slivinn :

I'm trying to extract large .tar file using pv.

pv large_file.tar.gz | tar -xcf /../MyFolder.

The pv command works like expected,showing the progress in the console.

I'm trying to split the stdout, to show the progress both in the console and save the same standout, to a file.

I tried doing so with tee, but couldn't make it work.

pv large_file.tar.gz | tee /tmp/strout.log | tar -xcf /../MyFolder

Any suggestions how can i display the progress to the console an in the same time save it to a file?

Thanks!

Neywat :

Not sure that your original command works, as there are several errors in the options given to tar.

Given that ../MyFolder exists, your first command need to be

    pv large_file.tar.gz | tar -xz -C ../MyFolder

If you insert tee call between pv and tar calls, then the whole chain works.

    pv large_file.tar.gz | tee /tmp/strout.log | tar -xz -C ../MyFolder

However i'm not sure it does what you expect. If you pipe pv output to tee, tee will pipe it to tar, and dump the same contents as the original tar to /tmp/strout.log, resulting in your tar extracted to ../MyFolder and copied to /tmp/strout.log.

EDIT
As suggested by @DownloadPizza, you can use process substitution (see How do I write stderr to a file while using "tee" with a pipe?). By using -f flag with pv, your command will become

    pv -f large_file.tar.gz 2> >(tee /tmp/strout.log) > >(tar -xz -C ../MyFolder)

and will produce expected output.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=6482&siteId=1