Last active
March 14, 2018 12:18
-
-
Save bgstack15/0bccc83672ac8ecdd5f6df0cc8e59511 to your computer and use it in GitHub Desktop.
Delayed cleanup of temp files in shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example script name: fetch | |
clean_fetch() { | |
# Delayed cleanup | |
if test -z "${FETCH_NO_CLEAN}" ; | |
then | |
nohup /bin/bash <<EOF 1>/dev/null 2>&1 & | |
sleep "${FETCH_CLEANUP_SEC:-300}" ; /bin/rm -r "${FETCH_TMPDIR:-NOTHINGTODELETE}" 1>/dev/null 2>&1 ; | |
EOF | |
fi | |
} | |
trap "__ec=$? ; clean_fetch ; trap '' {0..20} ; exit ${__ec} ;" {0..20} | |
FETCH_TMPDIR="$( mktemp -d )" | |
tmpfile1="$( TMPDIR="${FETCH_TMPDIR}" mktemp )" | |
tmpfile2="$( TMPDIR="${FETCH_TMPDIR}" mktemp )" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment