linuxshellpipeon-the-flyxz

Is it possible to pipe `script` to, for example, `xz` for on-the-fly compressing instead of a file or a device?


The title is the question.

As root, I tried script -a - | nice_xzfull file.xz where nice_xzfull=ionice -c 3 nice -n 20 xz -vvz9e --lzma2=dict=64MiB,mf=bt4,nice=273 --threads=3 (notice the last space) but instead script started and stopped, xz printed how the compressiong went, script stopping being evident by exit closing the SSH window instead of script closing and the file.xz being anywhere to be found.


Solution

  • script does not take - as standard output, thus your try failed. Fortunately, bash has the useful process substitution feature, which enables us to write

    script >(nice_xzfull >file.xz)
    

    (note the > before file.xz). The script option -a doesn't make sense here.