2009-05-23 13:47:59 +00:00
|
|
|
#! /bin/sh
|
|
|
|
# logclean.sh - maintenance script for logfiles generated by CommModule
|
|
|
|
# run this daily or weekly from cron
|
|
|
|
|
2018-09-06 10:25:38 +00:00
|
|
|
COMPRESS="xz -9 -M 1GiB" # compression program to use
|
|
|
|
COMPRESS_EXT=xz # file extension for compression program
|
|
|
|
|
2009-05-23 13:47:59 +00:00
|
|
|
syslog_error()
|
|
|
|
{
|
|
|
|
logger -i -t CommModule/logclean.sh -p user.err $1
|
|
|
|
}
|
|
|
|
|
|
|
|
syslog_notice()
|
|
|
|
{
|
|
|
|
logger -i -t CommModule/logclean.sh -p user.notice $1
|
|
|
|
}
|
|
|
|
|
|
|
|
# determine location of CommModule
|
|
|
|
if [ -d /home/cacert/www/CommModule ]
|
|
|
|
then # webdb server
|
|
|
|
cd /home/cacert/www/CommModule
|
|
|
|
elif [ -d /root/CommModule ]
|
|
|
|
then # signing server
|
|
|
|
cd /root/CommModule
|
|
|
|
else
|
|
|
|
echo "$0: cannot find CommModule directory" 1>&2
|
|
|
|
syslog_error "cannot find CommModule directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# compress logfiles which have not been modified in at least 48 hours
|
|
|
|
FILES=`find logfile20*.txt -mtime +1 -print`
|
|
|
|
if [ -n "${FILES}" ]
|
|
|
|
then
|
|
|
|
for F in ${FILES}
|
|
|
|
do
|
2018-09-06 10:25:38 +00:00
|
|
|
syslog_notice "Compressing ${F}" && ${COMPRESS} ${F}
|
2009-05-23 13:47:59 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# move compressed logfiles to oldlogs directory
|
2018-09-06 10:25:38 +00:00
|
|
|
FILES=`find logfile20*.txt.${COMPRESS_EXT} -print`
|
2009-05-23 13:47:59 +00:00
|
|
|
if [ -n "${FILES}" ]
|
|
|
|
then
|
|
|
|
mkdir -p oldlogs
|
|
|
|
for F in ${FILES}
|
|
|
|
do
|
|
|
|
syslog_notice "Moving ${F} to oldlogs" && mv ${F} oldlogs
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2009-05-24 18:08:23 +00:00
|
|
|
# delete old logfiles which have not been modified in at least 2.5+ years
|
2018-09-06 10:25:38 +00:00
|
|
|
FILES=`find oldlogs/logfile20*.txt.${COMPRESS_EXT} -mtime +913 -print`
|
2009-05-23 13:47:59 +00:00
|
|
|
if [ -n "${FILES}" ]
|
|
|
|
then
|
|
|
|
for F in ${FILES}
|
|
|
|
do
|
|
|
|
syslog_notice "Deleting ${F}" && rm -f ${F}
|
|
|
|
done
|
|
|
|
fi
|