From e10f0cc9103b27d579536c02c58654e07f4afa8e Mon Sep 17 00:00:00 2001 From: Wytze van der Raay Date: Sat, 23 May 2009 13:47:59 +0000 Subject: [PATCH] logclean.sh - maintenance script for logfiles generated by CommModule run this daily or weekly from cron --- CommModule/logclean.sh | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 CommModule/logclean.sh diff --git a/CommModule/logclean.sh b/CommModule/logclean.sh new file mode 100755 index 0000000..a35ed68 --- /dev/null +++ b/CommModule/logclean.sh @@ -0,0 +1,57 @@ +#! /bin/sh +# logclean.sh - maintenance script for logfiles generated by CommModule +# run this daily or weekly from cron + +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 + syslog_notice "Compressing ${F}" && bzip2 ${F} + done +fi + +# move compressed logfiles to oldlogs directory +FILES=`find logfile20*.txt.bz2 -print` +if [ -n "${FILES}" ] +then + mkdir -p oldlogs + for F in ${FILES} + do + syslog_notice "Moving ${F} to oldlogs" && mv ${F} oldlogs + done +fi + +# delete old logfiles which have not been modified in at least one year +FILES=`find oldlogs/logfile20*.txt.bz2 -mtime +365 -print` +if [ -n "${FILES}" ] +then + for F in ${FILES} + do + syslog_notice "Deleting ${F}" && rm -f ${F} + done +fi