Update cronjob that creates the 'today' symlink in /data/logs/*
This commit is contained in:
parent
30d159d86f
commit
9f1e0b51c8
8 changed files with 32 additions and 65 deletions
|
|
@ -1,56 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default configuration.
|
||||
LOGS_DIR="/var/log"
|
||||
DIR_MODE="0750"
|
||||
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.
|
||||
[[ -e /etc/default/rotate-logs-symlinks ]] && {
|
||||
# shellcheck disable=SC1091
|
||||
source /etc/default/rotate-logs-symlinks || {
|
||||
printf "%s: %s\\n" "${0##*/}" "failed reading /etc/default/rotate-logs-symlinks" >&2
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Process the directories in the logs directory.
|
||||
[[ -d "$LOGS_DIR" ]] && {
|
||||
TODAY="$(printf "%(%Y/%m/%d)T")"
|
||||
|
||||
umask "$UMASK"
|
||||
|
||||
# Process all the directories in the logs directory.
|
||||
for DIR in "$LOGS_DIR"/*/; do
|
||||
cd "$DIR" 2>/dev/null || {
|
||||
printf "%s: %s\\n" "${0##*/}" "failed to change directory to '$DIR'" >&2
|
||||
continue
|
||||
}
|
||||
|
||||
# Create a new logs directory for today.
|
||||
# shellcheck disable=SC2174
|
||||
mkdir -p -m "$DIR_MODE" "$TODAY" 2>/dev/null || {
|
||||
printf "%s: %s\\n" "${0##*/}" "failed to create directory '$DIR/$TODAY'" >&2
|
||||
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.
|
||||
( cd "$DIR" 2>/dev/null && ln -sfn "$TODAY" "today" 2>/dev/null ) || {
|
||||
printf "%s: %s\\n" "${0##*/}" "updating 'today' symlink failed" >&2
|
||||
continue
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
exit 0
|
||||
24
opt/sbin/cronjob-rotate-logs-today-symlink
Executable file
24
opt/sbin/cronjob-rotate-logs-today-symlink
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default configuration.
|
||||
LOGS_DIR="/data/logs"
|
||||
|
||||
# Process the directories in the $LOGS_DIR directory.
|
||||
[[ -d "$LOGS_DIR" ]] && {
|
||||
TODAY="$(printf "%(%Y/%m/%d)T")"
|
||||
|
||||
for DIR in "$LOGS_DIR"/*/; do
|
||||
cd "$DIR" 2>/dev/null || {
|
||||
printf "%s: %s\\n" "${0##*/}" "failed to change directory to '$DIR'" >&2
|
||||
continue
|
||||
}
|
||||
|
||||
# Create the 'today' symlink to the new location..
|
||||
ln -sfn "$TODAY" "today" 2>/dev/null || {
|
||||
printf "%s: %s\\n" "${0##*/}" "updating 'today' symlink failed in '$DIR'" >&2
|
||||
continue
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue