IHS: Script para log rotation do access log

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:

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) find $LOG_PATH -name "access_log_*" -type f -mtime +$LOG_RETENTION -print -delete >> $LOG cp $OUTPUT_LOG $OUTPUT_LOG_BACKUP > /dev/null cat /dev/null > $OUTPUT_LOG 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
 * 1) !/bin/bash
 * 1) delete files access_log_* before $LOG_RETENTION
 * 1) copy log file
 * 1) empty log file
 * 1) compress the log file

2) Change permission

chmod a+x rotate_ihs_access_log.sh

3) Putting on Cron:

Edit crontab using crontab -e

Add the following lines

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

Ver também

 * Definindo a URL padrão no IBM HTTP Server Apache
 * Apache:Redirecionando para pagina de Erro
 * Apache:Redirecionando de HTTP para HTTPS
 * Linux e Unix: Ferramentas de Monitoracao e Performance
 * AWSTATS: Configurando o AWSTATS


 * Mais Artigos sobre Apache HTTP Server