-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_old_log.sh
More file actions
executable file
·53 lines (50 loc) · 1.35 KB
/
clean_old_log.sh
File metadata and controls
executable file
·53 lines (50 loc) · 1.35 KB
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
#!/bin/bash
# delete old files,just save files in 30 days
DAY_DELETE_1="30"
# delete old files,just save files in 20 days
DAY_DELETE_2="20"
# delete old files,clear uncut log file, just save files in 60 days
DAY_DELETE_3="60"
declare -a APP_LOG_DIR_1
APP_LOG_DIR_1=(
/var/log/pc3.0
/var/log/apache2
/var/log/uclog
)
declare -a APP_LOG_DIR_2
APP_LOG_DIR_2=(
/var/log/pstnus
)
declare -a APP_LOG_DIR_3
APP_LOG_DIR_3=(
/var/log/tang
/var/log/tangjava
)
function clean_old_logfile_1()
{
# clean log file
for dir in ${APP_LOG_DIR_1[*]}
do
[ -d ${dir} ] && find ${dir} -regextype posix-extended -regex '.*\.(log|gz).*' -type f -mtime +${DAY_DELETE_1} -delete
done
}
function clean_old_logfile_2()
{
# clean log file
for dir in ${APP_LOG_DIR_2[*]}
do
[ -d ${dir} ] && find ${dir} -regextype posix-extended -regex '.*\.(log|gz).*' -type f -mtime +${DAY_DELETE_2} -delete
done
}
function clean_old_logfile_3()
{
# clean log file, clear uncut log file
for dir in ${APP_LOG_DIR_3[*]}
do
[ -d ${dir} ] && find ${dir} -regextype posix-extended -regex '.*\.(log|gz).?([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}){0,1}' -type f -mtime +${DAY_DELETE_3} -delete
[ -d ${dir} ] && find ${dir} . -type f -iname "*.log" -size +20G -exec dd if=/dev/null of={} \;
done
}
clean_old_logfile_1
clean_old_logfile_2
clean_old_logfile_3