Search code examples
bashtarzenity

Tar compress Zenity progress


I wish to show the progress with zenity of a Tar compression of a folder.

Consider the following code to compress the Document folder to bzip2.

(tar -cf - Documents | pv -n -s $(du -sb Documents | awk '{print $1}') \ 
| bzip2 > test.tar.bz2) | zenity --progress --percentage=0 

The progress is displayed in the terminal using pv by displaying the percentage line by line.

3
9
16
27
...

However, zenity does not display the progress and remains locked at 0%. When the process is complete, zenity displays 100%. How to fix my mistake and to view progression in zenity? Thanks


Solution

  • pv reports the progress on stderr, zenity reads from stdin, so it never sees what pv reports. When stdin is closed it switches to 100%.

    Try this, that should fix it:

    (tar -cf - Documents | pv -n -s $(du -sb Documents | awk '{print $1}') \ 
    | bzip2 > test.tar.bz2) 2>&1 | zenity --progress --percentage=0