Score:0

Output of find | xargs not redirecting to log file

us flag

I'm developing a Bash script which cleans up old data files periodically, and right now everything works except for the log file I'm trying to generate so I can see what it did.

The structure I'm using is (sorry for the variables):

find $datfold -maxdepth 1 -type f -name "$month-*-data.dat" -printf "%f\n" | xargs tar -czvf $month-data.tar.gz >> $log

The tar.gz part is working fine, it's just not sending any output to the $log file. What am I missing?

hr flag
I don't know; however you may want to consider using tar's `--files-from` to read names directly from stdin instead of using xargs ex. `... -printf "%f\n" | tar --files-from=- -czvf "$month-data.tar.gz" >> "$log"` or `... -printf "%f\0" | tar --null --files-from=- -czvf "$month-data.tar.gz" >> "$log"`
KneadToKnow avatar
us flag
I'll give that a try and see if it clears things up, thanks! Also, I noticed from your example that I had neglected to quote my variables at the end of my current command line, so I'm going to make sure that isn't causing a problem also.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.