#!/bin/bash
cd /www/wwwroot/chaosuan/runtime/log
current_month=$(date +%Y%m) # 获取当前年月份
previous_month=$(date -d "1 month ago" +%Y%m) # 获取上个月的年月份
folder_list=""
# 遍历文件夹,筛选出当前月份和上个月份的文件夹
for folder in *; do
folder_name=${folder%/} # 去除末尾的斜杠
if [[ $folder_name != $current_month && $folder_name != $previous_month ]]; then
folder_list+=" "$folder_name
fi
done
rm -rf $folder_list
删除除本月以及上个月的旧日志
最新推荐文章于 2024-07-12 18:42:17 发布