bash script to lazy tar to fifo as files arrive

bash script to lazy tar to fifo as files arrive

Here's the hypothetical scenario: I have an archival process where files are showing up and I append them to tar, and then the tar gets zipped. Something like this:

while sleep 1 ; do
    new_files="$(some-command-to-scan-for files)"
    tar --append --file xxx.tar $new_files
    if [ condition ] ; then break; fi
done

cat xxx.tar | gzip | dd of=/another/directory/xxx-$(date).tgz
rm xxx.tar

what I really want to happen is for tar to be created and zipped as the cycle goes, so that there is no need to temporary file. Which is not possible to do when you are appending, since you need to open existing file and seek to end. Here's the "sketch" of what I really want:

while sleep 1 ; do
    new_files="$(some-command-to-scan-for files)"
    tar --append --file - $new_files
    if [ condition ] ; then break; fi
done | gzip | dd of=/another/directory/xxx-$(date).tgz

Is there some way to append more files to tar when it goes to stdout?

verwandte Informationen