From 784380c3cac8837e879e7ba7ae07c19d8b8ca12e Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Sat, 4 Apr 2026 13:07:49 +0000 Subject: [PATCH] Include a cronjob to create 'today' symlink for logs. --- cronjob-rotate-logs-today-symlink | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 cronjob-rotate-logs-today-symlink diff --git a/cronjob-rotate-logs-today-symlink b/cronjob-rotate-logs-today-symlink new file mode 100755 index 0000000..f59a139 --- /dev/null +++ b/cronjob-rotate-logs-today-symlink @@ -0,0 +1,32 @@ +#!/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 new days' location. + umask 0755 + # shellcheck disable=SC2174 + mkdir -p -m 0755 "$LOGS_DIR/$TODAY" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "failed to create directory '$LOGS_DIR/$TODAY'" >&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