Skip to content

Instantly share code, notes, and snippets.

@ronin1
ronin1 / clean_tmp_files.sh
Created October 7, 2023 00:32
Bash Script to Remove Day old Files in /tmp directory that has no open file handles
#!/bin/bash
# Meant to be run nightly by a cron job on this box. This script will:
# - find a list of files that are 1 day old and has no current file handles attached
# - log these files into a: deleted.<day_of_the_month>.log file so we have a max log count (no need to clean up)
# - delete the files from disk
DRY_RUN=${DRY_RUN:-'0'}
CLR_TMP_DIR=${CLR_TMP_DIR:-'/tmp'}
CLR_TMP_LOG=${CLR_TMP_LOG:-"${HOME}/clr_tmp"}