On Sun, 31 May 2020, Laura Smith wrote:
A couple of notes on this quite useful script:
My mktemp does not support -p (FreeBSD 12.1) is I had to change the script to:
In my scripts I tend to create a tempdir and then tempfiles within that. It makes the cleanup routine neater, e.g. at the top of my scripts :
TEMP_DIR=$(mktemp -qd || { doLog "Failed to make temp dir !"; exit 1; }) rmTmpFiles() { rm -rf "${TEMP_DIR}"; } createTempFile() { local MYTEMP=$(mktemp -qp "${TEMP_DIR}" || doLog "Failed to create temp file"; exit 1); echo $MYTEMP; }
Also my backup scripts have locking procedures built-in so as to avoid race conditions.
You might also want a trap handler that does a cleanup in case something goes sideways in the middle of processing e.g.
trap rmTmpFiles 0
Joseph Tam jtam.home@gmail.com