KSH - I've got a script that is generating a number of log files like this:
y=`date +"%y"`
m=`date +"%m"`
$LOG_DIR/tuscprof_tbl_$y$m.log
I only want to keep the current 2 months' worth of files (current month and prior month). So I'm trying to come up with a way to delete any file that contains a filename month that is -2 from current month.
I thought I could do it like this, but it's not working:
Any help appreciated...
y=`date +"%y"`
m=`date +"%m"`
$LOG_DIR/tuscprof_tbl_$y$m.log
I only want to keep the current 2 months' worth of files (current month and prior month). So I'm trying to come up with a way to delete any file that contains a filename month that is -2 from current month.
I thought I could do it like this, but it's not working:
Code:
if [[ -e $LOG_DIR/*_$(($y))*.log && -e $LOG_DIR/*_*$(($m - 2)).log ]]
then rm $LOG_DIR/*_*$(($m - 2)).log
fi
if [[ -e $LOG_DIR/*_$(($y - 1))%*.log && ! $m -eq 01 ]]
then rm $LOG_DIR/*_$(($y - 1))%*.log
fi
Any help appreciated...