forked from blacklabelops/logrotate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
logrotateCreateConf.sh
executable file
·77 lines (64 loc) · 1.98 KB
/
logrotateCreateConf.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#
# Creation of Logfile
function handleSingleFile() {
local singleFile="$1"
local file_owner_user=$(stat -c %U ${singleFile})
local file_owner_group=$(stat -c %G ${singleFile})
local new_logrotate_entry=$(createLogrotateConfigurationEntry "${singleFile}" "${file_owner_user}" "${file_owner_group}" "${logrotate_copies}" "${logrotate_logfile_compression}" "${logrotate_logfile_compression_delay}" "${logrotate_mode}" "${logrotate_interval}" "${logrotate_size}" "${logrotate_dateformat}" "${logrotate_minsize}" "${logrotate_maxage}" "${logrotate_prerotate}" "${logrotate_postrotate}")
echo "Inserting new ${singleFile} to /usr/bin/logrotate.d/logrotate.conf"
insertConfigurationEntry "$new_logrotate_entry" "/usr/bin/logrotate.d/logrotate.conf"
}
# ----- Logfile Crawling ------
log_dirs=""
if [ -n "${LOGS_DIRECTORIES}" ]; then
log_dirs=${LOGS_DIRECTORIES}
else
log_dirs=${log_dir}
fi
logs_ending="log"
LOGS_FILE_ENDINGS_INSTRUCTION=""
if [ -n "${LOG_FILE_ENDINGS}" ]; then
logs_ending=${LOG_FILE_ENDINGS}
fi
SAVEIFS=$IFS
IFS=' '
COUNTER=0
for ending in $logs_ending
do
if [ "$COUNTER" -eq "0" ]; then
LOGS_FILE_ENDINGS_INSTRUCTION="$LOGS_FILE_ENDINGS_INSTRUCTION -iname "*.${ending}""
else
LOGS_FILE_ENDINGS_INSTRUCTION="$LOGS_FILE_ENDINGS_INSTRUCTION -o -iname "*.${ending}""
fi
let COUNTER=COUNTER+1
done
IFS=$SAVEIFS
for d in ${log_dirs}
do
log_files=$(find ${d} -type f $LOGS_FILE_ENDINGS_INSTRUCTION) || continue
for f in ${log_files};
do
if [ -f "${f}" ]; then
echo "Found new file $f, Processing..."
handleSingleFile "$f"
fi
done
done
# ----- Take all Log in Subfolders ------
all_log_dirs=""
if [ -n "${ALL_LOGS_DIRECTORIES}" ]; then
all_log_dirs=${ALL_LOGS_DIRECTORIES}
fi
for d in ${all_log_dirs}
do
log_files=$(find ${d} -type f);
for f in ${log_files};
do
if [ -f "${f}" ]; then
echo "Found new file $f, Processing..."
handleSingleFile "$f"
fi
done
done
cat /usr/bin/logrotate.d/logrotate.conf