Merge branch 'bug-1339' into release
[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 syslog_error()
6 {
7 logger -i -t CommModule/logclean.sh -p user.err $1
8 }
9
10 syslog_notice()
11 {
12 logger -i -t CommModule/logclean.sh -p user.notice $1
13 }
14
15 # determine location of CommModule
16 if [ -d /home/cacert/www/CommModule ]
17 then # webdb server
18 cd /home/cacert/www/CommModule
19 elif [ -d /root/CommModule ]
20 then # signing server
21 cd /root/CommModule
22 else
23 echo "$0: cannot find CommModule directory" 1>&2
24 syslog_error "cannot find CommModule directory"
25 exit 1
26 fi
27
28 # compress logfiles which have not been modified in at least 48 hours
29 FILES=`find logfile20*.txt -mtime +1 -print`
30 if [ -n "${FILES}" ]
31 then
32 for F in ${FILES}
33 do
34 syslog_notice "Compressing ${F}" && bzip2 ${F}
35 done
36 fi
37
38 # move compressed logfiles to oldlogs directory
39 FILES=`find logfile20*.txt.bz2 -print`
40 if [ -n "${FILES}" ]
41 then
42 mkdir -p oldlogs
43 for F in ${FILES}
44 do
45 syslog_notice "Moving ${F} to oldlogs" && mv ${F} oldlogs
46 done
47 fi
48
49 # delete old logfiles which have not been modified in at least 2.5+ years
50 FILES=`find oldlogs/logfile20*.txt.bz2 -mtime +913 -print`
51 if [ -n "${FILES}" ]
52 then
53 for F in ${FILES}
54 do
55 syslog_notice "Deleting ${F}" && rm -f ${F}
56 done
57 fi