#!/bin/ksh
#This script will rotate all log files
#that are included in DIRLIST below.
#Read in log file directory list from the control file above
DIRLIST=`cat $home/scripts/log_list.ctrl`
for DIRECTORY in $DIRLIST
do
#Rotate archived access and error log files
#If an archived access or errors file doesn't exist,
#then create it.
if [[ ! -a ${DIRECTORY}.05.gz ]];
then
touch ${DIRECTORY}.05.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.05.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.04.gz ]];
then
touch ${DIRECTORY}.04.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.04.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.03.gz ]];
then
touch ${DIRECTORY}.03.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.03.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.02.gz ]];
then
touch ${DIRECTORY}.02.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.02.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.01.gz ]];
then
touch ${DIRECTORY}.01
touch ${DIRECTORY}.01.gz
#Puts entry into log file.
echo "- $(date): The following log files didn't exist and are now created: $DIRECTORY.01 and $DIRECTORY.01.gz" >> $home/output/wlLogRotate.log
fi
#If all of the archived log files are there, then rotate them
if [[ -a ${DIRECTORY}.05.gz ]] && [[ -a ${DIRECTORY}.04.gz ]] && [[ -a ${DIRECTORY}.03.gz ]] && [[ -a ${DIRECTORY}.02.gz ]] && [[ -a ${DIRECTORY}.01.gz ]];
then
#Log files
cp -f ${DIRECTORY}.04.gz ${DIRECTORY}.05.gz
cp -f ${DIRECTORY}.03.gz ${DIRECTORY}.04.gz
cp -f ${DIRECTORY}.02.gz ${DIRECTORY}.03.gz
cp -f ${DIRECTORY}.01.gz ${DIRECTORY}.02.gz
#Puts entry into log file.
echo "- $(date): The following log files have been rotated: $DIRECTORY" >> $home/output/wlLogRotate.log
#Copy current log files
cp -f ${DIRECTORY} ${DIRECTORY}.01
#Puts entry into log file.
echo "- $(date): The following log files have been copied to version .01: $DIRECTORY" >> $home/output/wlLogRotate.log
#Remove the .01.gz files
rm -f ${DIRECTORY}.01.gz
#Puts entry into log file.
echo "- $(date): The following log .01.gz files have been removed: $DIRECTORY" >> $home/output/wlLogRotate.log
#Zip the log files
gzip ${DIRECTORY}.01
#Puts entry into log file.
echo "- $(date): The following .01 log files have been gziped: $DIRECTORY" >> $home/output/wlLogRotate.log
#Null out the working log files so that
#they go down to zero file size
cat /dev/null > ${DIRECTORY}
#Puts entry into log file.
echo "- $(date): The following log files have been nulled out: $DIRECTORY" >> $home/output/wlLogRotate.log
fi
done
#This script will rotate all log files
#that are included in DIRLIST below.
#Read in log file directory list from the control file above
DIRLIST=`cat $home/scripts/log_list.ctrl`
for DIRECTORY in $DIRLIST
do
#Rotate archived access and error log files
#If an archived access or errors file doesn't exist,
#then create it.
if [[ ! -a ${DIRECTORY}.05.gz ]];
then
touch ${DIRECTORY}.05.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.05.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.04.gz ]];
then
touch ${DIRECTORY}.04.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.04.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.03.gz ]];
then
touch ${DIRECTORY}.03.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.03.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.02.gz ]];
then
touch ${DIRECTORY}.02.gz
#Puts entry into log file.
echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.02.gz" >> $home/output/wlLogRotate.log
fi
if [[ ! -a ${DIRECTORY}.01.gz ]];
then
touch ${DIRECTORY}.01
touch ${DIRECTORY}.01.gz
#Puts entry into log file.
echo "- $(date): The following log files didn't exist and are now created: $DIRECTORY.01 and $DIRECTORY.01.gz" >> $home/output/wlLogRotate.log
fi
#If all of the archived log files are there, then rotate them
if [[ -a ${DIRECTORY}.05.gz ]] && [[ -a ${DIRECTORY}.04.gz ]] && [[ -a ${DIRECTORY}.03.gz ]] && [[ -a ${DIRECTORY}.02.gz ]] && [[ -a ${DIRECTORY}.01.gz ]];
then
#Log files
cp -f ${DIRECTORY}.04.gz ${DIRECTORY}.05.gz
cp -f ${DIRECTORY}.03.gz ${DIRECTORY}.04.gz
cp -f ${DIRECTORY}.02.gz ${DIRECTORY}.03.gz
cp -f ${DIRECTORY}.01.gz ${DIRECTORY}.02.gz
#Puts entry into log file.
echo "- $(date): The following log files have been rotated: $DIRECTORY" >> $home/output/wlLogRotate.log
#Copy current log files
cp -f ${DIRECTORY} ${DIRECTORY}.01
#Puts entry into log file.
echo "- $(date): The following log files have been copied to version .01: $DIRECTORY" >> $home/output/wlLogRotate.log
#Remove the .01.gz files
rm -f ${DIRECTORY}.01.gz
#Puts entry into log file.
echo "- $(date): The following log .01.gz files have been removed: $DIRECTORY" >> $home/output/wlLogRotate.log
#Zip the log files
gzip ${DIRECTORY}.01
#Puts entry into log file.
echo "- $(date): The following .01 log files have been gziped: $DIRECTORY" >> $home/output/wlLogRotate.log
#Null out the working log files so that
#they go down to zero file size
cat /dev/null > ${DIRECTORY}
#Puts entry into log file.
echo "- $(date): The following log files have been nulled out: $DIRECTORY" >> $home/output/wlLogRotate.log
fi
done