-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean_log.sh
executable file
·62 lines (48 loc) · 1.23 KB
/
clean_log.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#****************************************************************
# clean_log.sh
# written by Saara Huhmarniemi
# Feb 10, 2006
#
# Clean the corpus tmp directory
#
# $Id$
#****************************************************************
corpdir=/usr/local/share/corp
log_dirs="$corpdir/tmp
$corpdir/upload"
year_month=`date +%Y-%b`
month_day=`date +%b-%d`
# Move the log files in tmp and upload directory to tarball,
# and store it under subdirectory old/
# The script is supposed to be run each day before midnight.
# one tarball contains the log files of that day.
# Remove .tmp.xml -files altogether.
create_tar ()
{
for dir in "$@"
do
echo "cleaning dir $dir..."
log_files=`find $dir -maxdepth 1 -name "$month_day-*"`
tar_file=$dir/log/$year_month/$month_day.tar
tmp_files=`find $dir -maxdepth 1 -name "*.tmp.xml"`
rm -rf $tmp_files
if [ -z "$log_files" ]; then
continue
fi
mkdir -p $dir/log/$year_month
if [ ! -e $tar_file.gz ]
then
tar -c --file=$tar_file $log_files
else
gunzip $tar_file.gz
tar -A --file=$tar_file $log_files
fi
gzip -f $tar_file
chgrp -R cvs $dir/log/$year_month
rm -rf $log_files
done
exit 0
}
create_tar $log_dirs
exit 0