-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog-roller.sh
43 lines (28 loc) · 1.4 KB
/
log-roller.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
## 'home' directory where the jboss apps reside
LOG_DIR="/opt/jboss/stable/server/"
## compressed logs older then this
COMPRESS_AGE=7
## delete compressed logs older then this
DEL_AGE=90
## where to store output; this will include which files were compressed and which files were deleted
WORK_DIR=$(dirname $(readlink -f $0))
LOG_FILE="$WORK_DIR/log-roller.log"
MY_DATE=`date +%F" "%T`
cd "$LOG_DIR"
## find all wrapper.log files & empty them
## delete all old/compressed wrapper.log files (if they exist)
find . -type f -name "wrapper.log" -not -name "*.gz" -exec tee {} </dev/null \;
find . -type f -name "wrapper.log.*" -exec rm {} \;
echo >> "$LOG_FILE"
## find all *.gz (f)iles older then $DEL_AGE, first "print" filename to log, then delete it
echo "$MY_DATE - Deleting these files from `pwd`:" >> "$LOG_FILE"
find . -type f -name "*.gz" -mtime +$DEL_AGE -print >> "$LOG_FILE"
find . -type f -name "*.gz" -mtime +$DEL_AGE -exec rm -f {} \;
echo "Done." >> "$LOG_FILE" ; echo >> "$LOG_FILE"
## find all "rolled" log files (i.e. server.log.2008-11-24), first "print" filename to log, then gzip the file
echo "$MY_DATE - compressing these files from `pwd`:" >> "$LOG_FILE"
find . -type f -name "*.log.*" -not -name "*.gz" -mtime +$COMPRESS_AGE -print >> "$LOG_FILE"
find . -type f -name "*.log.*" -not -name "*.gz" -mtime +$COMPRESS_AGE -exec gzip {} \;
echo "Done." >> "$LOG_FILE" ; echo >> "$LOG_FILE"
exit 0