Skip to main content

自动清除15天前的日志脚本

#!/bin/bash

#0 1 * * * /home/shuncom/auto_del_sz_log.sh

# 设置变量
target_dir="/home/shuncom/services/log/sz_server"
log_file="/home/shuncom/log/del_driver_log.log"
current_time="$(date '+%Y-%m-%d %H:%M:%S')"

# 执行删除操作并记录日志
echo "[$current_time] Start deleting files older than 15 days in $target_dir" >> "$log_file"

find "$target_dir" -type f -mtime +15 -print -delete >> "$log_file" 2>&1

echo "[$current_time] Deletion complete." >> "$log_file"
echo "---------------------------------------------" >> "$log_file"