IHS: Script para log rotation do access log

From Wiki

Script para rotacionamento de log do IBM HTTP Server

English: Script for log rotation on IBM HTTP Server


Script

1) Ir para o diretório

cd /opt/IBM/HTTPServer/bin/

2) Criar o arquivo rotate_ihs_access_log.sh e colar o seguinte conteúdo:

#!/bin/bash
LOG_RETENTION=90
LOG_PATH="/opt/IBM/HTTPServer/logs"
LOG="/var/log/rotate_ihs_access_log.log"
DATE_TODAY=$(date +"%Y-%m-%d")
DATE_YESTERDAY=$(date --date="yesterday" +"%Y-%m-%d")
OUTPUT_LOG="$LOG_PATH/access_log"
OUTPUT_LOG_BACKUP="$LOG_PATH/access_log_$DATE_YESTERDAY.log"

echo "" >> $LOG
echo "IHS Rotate:: Script Start -- $(date +%Y%m%d_%H%M)" >> $LOG
START_TIME=$(date +%s)

# delete files access_log_* before $LOG_RETENTION
find $LOG_PATH -name "access_log_*"  -type f -mtime +$LOG_RETENTION -print -delete >> $LOG

# copy log file 
cp $OUTPUT_LOG $OUTPUT_LOG_BACKUP > /dev/null
  
# empty log file 
cat /dev/null > $OUTPUT_LOG

# compress the log file
bzip2 $OUTPUT_LOG_BACKUP > /dev/null

END_TIME=$(date +%s)
ELAPSED_TIME=$(expr $END_TIME - $START_TIME)
echo "IHS Rotate:: Script End   -- $(date +%Y%m%d_%H%M)" >> $LOG
echo "IHS Rotate:: Elapsed Time -- $(date -d 00:00:$ELAPSED_TIME +%Hh:%Mm:%Ss) "  >> $LOG

2) Change permission

chmod a+x rotate_ihs_access_log.sh


3) Putting on Cron:

Edit crontab using crontab -e

Add the following lines

###### Script for log rotation on IBM HTTP Server######
0 1 * * * /opt/IBM/HTTPServer/bin/rotate_ihs_access_log.sh

Ver também