-
Notifications
You must be signed in to change notification settings - Fork 0
tempFolderClean
holzkohlengrill edited this page Dec 15, 2023
·
2 revisions
Script to periodically clean contents temporary folders. Change paths within the scripts to your needs.
######################################
# Temp folder cleaner
######################################
# paths
pathTemp="/path/to/temp/folder"
pathLog="/path/for/log/file"
logfile="${pathLog}/log.txt"
rm "${pathTemp}/This_directory_will_be_emptied_every_sunday"
echo "Writing log of files in temp folder (\`${pathLog}\`)"
# Preparing header to append to logfile
echo "######################################" >>${logfile}
echo "# $(date +%F\ %T)" >>${logfile}
echo "--------------------------------------" >>${logfile}
# Writing contents of `pathTemp` in logfile (local dir @`pathLog`)
echo "File in temp folder before deletion:" >>${logfile}
printf "\n" >>${logfile}
if [[ "$(ls -A ${pathTemp})" ]] # true if length of string is non-zero
then
echo "Path is not empty"
tree ${pathTemp} >>${logfile}
#echo "$(find ${pathTemp})" >>${logfile} # if tree is not available
echo "Deletion started..."
find ${pathTemp}/* -delete # delete all files and dirs
else
echo "path is EMPTY"
echo "<Folder was empty>" >>${logfile}
fi
printf "\n" >>${logfile}
> ${pathTemp}/This_directory_will_be_emptied_every_sunday
echo "Everything clean."
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License *.
Code (snippets) are licensed under a MIT License *.
* Unless stated otherwise