Update log rotation cronjob.
This commit is contained in:
parent
a312a4d12d
commit
86c4e99795
1 changed files with 14 additions and 3 deletions
|
|
@ -5,6 +5,9 @@ LOGS_DIR="/var/log"
|
||||||
DIR_MODE="0750"
|
DIR_MODE="0750"
|
||||||
UMASK="027"
|
UMASK="027"
|
||||||
|
|
||||||
|
# This array may be used in the defaults file.
|
||||||
|
declare -A CREATE_DIRS
|
||||||
|
|
||||||
# Allow /etc/default/rotate-logs-symlinks to override default configuration.
|
# Allow /etc/default/rotate-logs-symlinks to override default configuration.
|
||||||
[[ -e /etc/default/rotate-logs-symlinks ]] && {
|
[[ -e /etc/default/rotate-logs-symlinks ]] && {
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
|
|
@ -21,7 +24,7 @@ UMASK="027"
|
||||||
umask "$UMASK"
|
umask "$UMASK"
|
||||||
|
|
||||||
# Process all the directories in the logs directory.
|
# Process all the directories in the logs directory.
|
||||||
for DIR in "$LOGS_DIR"/*; do
|
for DIR in "$LOGS_DIR"/*/; do
|
||||||
cd "$DIR" 2>/dev/null || {
|
cd "$DIR" 2>/dev/null || {
|
||||||
printf "%s: %s\\n" "${0##*/}" "failed to change directory to '$DIR'" >&2
|
printf "%s: %s\\n" "${0##*/}" "failed to change directory to '$DIR'" >&2
|
||||||
continue
|
continue
|
||||||
|
|
@ -34,9 +37,17 @@ UMASK="027"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If configured to do so for this directory, create sub directories.
|
||||||
|
for CREATE_DIR in ${CREATE_DIRS[$(printf "$DIR" | awk -F / -e '{print $4}')]}; do
|
||||||
|
mkdir -p -m "$DIR_MODE" "$TODAY/$CREATE_DIR" 2>/dev/null || {
|
||||||
|
printf "%s: %s\\n" "${0##*/}" "failed to create directory '$DIR/$TODAY/$CREATE_DIR'" >&2
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
# Create a 'today' symlink to the new days' directory.
|
# Create a 'today' symlink to the new days' directory.
|
||||||
( cd "$DIR" 2>/dev/null && ln -sf "$TODAY" "today" 2>/dev/null ) || {
|
( cd "$DIR" 2>/dev/null && ln -sfn "$TODAY" "today" 2>/dev/null ) || {
|
||||||
printf "%s: %s\\n" "${0##*/}" "creating 'today' symlink failed" >&2
|
printf "%s: %s\\n" "${0##*/}" "updating 'today' symlink failed" >&2
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue