27 lines
622 B
Bash
27 lines
622 B
Bash
#!/usr/bin/env bash
|
|
|
|
# Set the log directory
|
|
LOG_DIR="/var/log/httpd"
|
|
|
|
# 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
|
|
|