Summary: A bash script for (log) file retention.
Date: 27 Jun 2011
Refactor: 16 April 2025: Checked links and formatting.
This is a simple retention script used on SLES. It can be easily modified to add directories for cleanup.
#!/bin/bash ######################################################################################################################## # Author : Sjoerd Hooft # Date Initial Version: 27 Jun 2011 # Comments: sjoerd_ @ _getshifting.com # # Description: # This is a default retention script for the /tmp directory on SLES linux servers. # # Recommendations: # The script is designed for a 120 column terminal. # The running user must be root. # # Changes: # Please comment on your changes to the script (your name and email address, line number, description): ######################################################################################################################## # Script Variables HOSTNAME_SHORT=`hostname -s` BASEDIR=`dirname $0` WHATAMI=`basename $0` LOGFILE="$BASEDIR/$WHATAMI.log" DATE=`date +%Y%m%d` BOLD=`tput bold` BOLDOFF=`tput sgr0` TOMAIL=it_getshifting.com # Send all output to logfile exec > $LOGFILE 2>&1 # Retention Variables RETENTIONTIME=+7 TMP=/tmp # Start Retention find $TMP/. -mtime ${RETENTIONTIME} -print -exec rm -rf {} \; >> $LOGFILE ### MAIL Results cat $LOGFILE | mail -s "Result Retention ${HOSTNAME_SHORT}" $TOMAIL ### End of Script exit 0