Merge branch 'bug-1459' into release (Emergency bugfix)
[cacert-devel.git] / CommModule / logclean.sh
1 #! /bin/sh
2 # logclean.sh - maintenance script for logfiles generated by CommModule
3 # run this daily or weekly from cron
4
5 COMPRESS="xz -9 -M 1GiB" # compression program to use
6 COMPRESS_EXT=xz # file extension for compression program
7
8 syslog_error()
9 {
10 logger -i -t CommModule/logclean.sh -p user.err $1
11 }
12
13 syslog_notice()
14 {
15 logger -i -t CommModule/logclean.sh -p user.notice $1
16 }
17
18 # determine location of CommModule
19 if [ -d /home/cacert/www/CommModule ]
20 then # webdb server
21 cd /home/cacert/www/CommModule
22 elif [ -d /root/CommModule ]
23 then # signing server
24 cd /root/CommModule
25 else
26 echo "$0: cannot find CommModule directory" 1>&2
27 syslog_error "cannot find CommModule directory"
28 exit 1
29 fi
30
31 # compress logfiles which have not been modified in at least 48 hours
32 FILES=`find logfile20*.txt -mtime +1 -print`
33 if [ -n "${FILES}" ]
34 then
35 for F in ${FILES}
36 do
37 syslog_notice "Compressing ${F}" && ${COMPRESS} ${F}
38 done
39 fi
40
41 # move compressed logfiles to oldlogs directory
42 FILES=`find logfile20*.txt.${COMPRESS_EXT} -print`
43 if [ -n "${FILES}" ]
44 then
45 mkdir -p oldlogs
46 for F in ${FILES}
47 do
48 syslog_notice "Moving ${F} to oldlogs" && mv ${F} oldlogs
49 done
50 fi
51
52 # delete old logfiles which have not been modified in at least 2.5+ years
53 FILES=`find oldlogs/logfile20*.txt.${COMPRESS_EXT} -mtime +913 -print`
54 if [ -n "${FILES}" ]
55 then
56 for F in ${FILES}
57 do
58 syslog_notice "Deleting ${F}" && rm -f ${F}
59 done
60 fi