简体   繁体   中英

Generate checksum during archive file creation under bash

I want to generate the checksum of a file when an archive is created, rather that read the data twice. Some of the backup archives are rather large. The script is going on bash hosts so installing zsh isn't an option. I have it working under zsh, but I am having trouble porting it for bash.

tar cf - folder | pigz -n > folder.tar.gz | md5sum | sed -e s/-/folder.tar.gz/g | tee sum.md5

Verify checksum

md5sum -c sum.md5

It works how I want under zsh , but when I execute it under bash :

d41d8cd98f00b204e9800998ecf8427e  folder.tar.gz
folder.tar.gz: FAILED
md5sum: WARNING: 1 computed checksum did NOT match

md5sum is receiving empty input, which is expected but not what I want it to do. ;)

The pigz -n > folder.tar.gz |... part of the pipeline depends on zsh'smultios feature to replicate the output from pigz to both folder.tar.gz and the rest of the pipeline. bash (and most other shells) don't have this feature, but you can replicate it with tee :

... | pigz -n | tee folder.tar.gz | ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM