2024-10-14 19:15:11 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Set the log directory
|
2024-10-15 02:30:51 +00:00
|
|
|
LOG_DIR="/var/log/httpd"
|
2024-10-14 19:15:11 +00:00
|
|
|
|
|
|
|
# Get current date
|
|
|
|
DATE=$(date +%Y%m%d)
|
|
|
|
|
|
|
|
# Rotate access log
|
|
|
|
if [ -f "$LOG_DIR/access_log" ]; then
|
|
|
|
cp "$LOG_DIR/access_log" "$LOG_DIR/access_log.$DATE"
|
|
|
|
cat /dev/null > "$LOG_DIR/access_log"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Rotate error log
|
|
|
|
if [ -f "$LOG_DIR/error_log" ]; then
|
|
|
|
cp "$LOG_DIR/error_log" "$LOG_DIR/error_log.$DATE"
|
|
|
|
cat /dev/null > "$LOG_DIR/error_log"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Compress logs older than 3 days
|
|
|
|
find "$LOG_DIR" -name "*.log.*" -type f -mtime +3 -exec gzip {} \;
|
|
|
|
|
|
|
|
# Delete logs older than 7 days
|
|
|
|
find "$LOG_DIR" -name "*.log.*" -type f -mtime +7 -delete
|
|
|
|
|