如果你使用的是 MySQL 8.0 或以上版本,可能需要在数据库连接 URL 中添加
#!/bin/bash
# Define the directory where logs are stored
LOG_DIR="/data/scripts"
# Define the maximum file size in bytes (10GB = 10 * 1024 * 1024 * 1024)
MAX_SIZE=$((10*1024*1024*1024))
# Log file for recording execution logs
LOG_FILE="/var/log/cleanup_logs.log"
# Log the current date/time and action
echo "$(date +'%Y-%m-%d %H:%M:%S') - Starting log cleanup" >> "$LOG_FILE"
# Find and delete log files larger than MAX_SIZE bytes recursively
find "$LOG_DIR" -type f -name "*.log" -size +$MAX_SIZEc -print0 | while IFS= read -r -d '' file; do
echo "$(date +'%Y-%m-%d %H:%M:%S') - Deleting $file" >> "$LOG_FILE"
rm -f "$file"
done
# Log the completion
echo "$(date +'%Y-%m-%d %H:%M:%S') - Log cleanup completed" >> "$LOG_FILE"
Ubuntu 系统重启服务系统
报错解释: