Skip to content

Instantly share code, notes, and snippets.

@toodooleedoo
Last active October 19, 2017 00:26
Show Gist options
  • Save toodooleedoo/0d312d83e8cb543a6262 to your computer and use it in GitHub Desktop.
Save toodooleedoo/0d312d83e8cb543a6262 to your computer and use it in GitHub Desktop.
#AEM #CQ Rotate Logs

#CQ #NIX Rotate Logs

Rotates AEM/CQ logs

#!/bin/sh
#
#CQ Log Rotater
#
#This script will rotate logs in each CQ related log directory to its relative folders archive directory.
#Eventually these logs get zipped and after time removed.
#
######## INSTALLATION INSTRUCTIONS #########
#
# 1) Copy this to CQ crx-quickstart directory.
# 2) Add this to cron
# 0 0 * * * cd /apps/mirror/AAA/crx-quickstart/;./rotate_logs.sh > /dev/null 2>&1
#
############################################
#
#Author: Eric Soukenka
#Date: 18Apr12
#
#
DAYS_TO_ZIP=2;
DAYS_TO_DELETE=7;
ID=${RANDOM};
TIMESTAMP=`date "+%d%b%Y" --date="1 day ago"`
if [ ! -f system.id ]; then
echo "You do not appear to be inside crx-quickstart directory";
exit;
fi
APP_LOGS=./logs/;
CRX_LOGS=./logs/crx/;
SERVER_LOGS=./server/logs/;
if [ ! -d ${APP_LOGS}/archive ]; then
mkdir -p ${APP_LOGS}/archive;
fi
cat ${APP_LOGS}/error.log >> ${APP_LOGS}/archive/error.log_${TIMESTAMP}; 2>/dev/null
cat ${APP_LOGS}/request.log >> ${APP_LOGS}/archive/request.log_${TIMESTAMP}; 2>/dev/null
cat ${APP_LOGS}/access.log >> ${APP_LOGS}/archive/access.log_${TIMESTAMP}; 2>/dev/null
cat ${APP_LOGS}/server.log >> ${APP_LOGS}/archive/server.log_${TIMESTAMP}; 2>/dev/null
cat ${APP_LOGS}/stdout.log >> ${APP_LOGS}/archive/stdout.log_${TIMESTAMP}; 2>/dev/null
cat ${APP_LOGS}/stderr.log >> ${APP_LOGS}/archive/stderr.log_${TIMESTAMP}; 2>/dev/null
echo "" > ${APP_LOGS}/error.log;
echo "" > ${APP_LOGS}/request.log;
echo "" > ${APP_LOGS}/access.log;
echo "" > ${APP_LOGS}/stdout.log;
echo "" > ${APP_LOGS}/stderr.log;
for f in `ls ${APP_LOGS}/error.log.* 2>/dev/null`
do
mv ${f} ${APP_LOGS}/archive/`basename \${f}`_${TIMESTAMP}
done;
if [ ! -d ${CRX_LOGS}/archive ]; then
mkdir -p ${CRX_LOGS}/archive;
fi
for f in `ls ${CRX_LOGS}/error.log.* 2>/dev/null`
do
mv ${f} ${CRX_LOGS}/archive/`basename \${f}`_${TIMESTAMP}
done;
cat ${CRX_LOGS}/error.log >> ${CRX_LOGS}/archive/error.log_${TIMESTAMP};
cat ${CRX_LOGS}/translation.log >> ${CRX_LOGS}/archive/translation.log_${TIMESTAMP};
echo "" > ${CRX_LOGS}/error.log
echo "" > ${CRX_LOGS}/translation.log
if [ ! -d ${SERVER_LOGS}/archive ]; then
mkdir -p ${SERVER_LOGS}/archive;
fi
cat ${SERVER_LOGS}/access.log >> ${SERVER_LOGS}/archive/access.log_${TIMESTAMP};
cat ${SERVER_LOGS}/startup.log >> ${SERVER_LOGS}/archive/startup.log_${TIMESTAMP};
echo "" > ${SERVER_LOGS}/access.log
echo "" > ${SERVER_LOGS}/startup.log
find ${APP_LOGS}/archive/ -mtime +${DAYS_TO_ZIP} -exec gzip '{}' \; 2>/dev/null
find ${CRX_LOGS}/archive/ -mtime +${DAYS_TO_ZIP} -exec gzip '{}' \; 2>/dev/null
find ${SERVER_LOGS}/archive/ -mtime +${DAYS_TO_ZIP} -exec gzip '{}' \; 2>/dev/null
find ${APP_LOGS}/archive/ -mtime +${DAYS_TO_DELETE} -exec rm -f '{}' \; 2>/dev/null
find ${CRX_LOGS}/archive/ -mtime +${DAYS_TO_DELETE} -exec rm -f '{}' \; 2>/dev/null
find ${SERVER_LOGS}/archive/ -mtime +${DAYS_TO_DELETE} -exec rm -f '{}' \; 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment