From bcb1956bbea19350bcb3c1bc04a0005397fd98cd Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sun, 24 May 2026 21:12:28 -0400 Subject: [PATCH] feat(varaverk): append logs per run with timestamp separator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit run_job.sh was overwriting the log on every cron fire, making it impossible to see run history. Switch to append mode, print a ── YYYY-MM-DD HH:MM:SS ── separator before each run, and trim to the last 1000 lines after each run to keep logs bounded. --- .../usr/local/emhttp/plugins/varaverk/run_job.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Plugin/usr/local/emhttp/plugins/varaverk/run_job.sh b/Plugin/usr/local/emhttp/plugins/varaverk/run_job.sh index b601cb9..77518f4 100644 --- a/Plugin/usr/local/emhttp/plugins/varaverk/run_job.sh +++ b/Plugin/usr/local/emhttp/plugins/varaverk/run_job.sh @@ -5,7 +5,7 @@ # Usage: bash run_job.sh [flags...] # # Writes: /var/log/varaverk/.json — status, timestamps, exit code, pid -# /var/log/varaverk/.log — latest run output (overwritten each run) +# /var/log/varaverk/.log — appended per run, trimmed to LOG_MAX_LINES # # Status values: running → ok (exit 0) | warn (exit 1) | error (exit 2+) @@ -17,6 +17,7 @@ LOG_DIR="/var/log/varaverk" BASE="${JOB_ID%.sh}" LOG_FILE="$LOG_DIR/$BASE.log" STAT_FILE="$LOG_DIR/$BASE.json" +LOG_MAX_LINES=1000 mkdir -p "$(dirname "$LOG_FILE")" "$(dirname "$STAT_FILE")" @@ -24,7 +25,10 @@ START=$(date +%s) printf '{"id":"%s","status":"running","start":%s,"pid":%s}\n' \ "$JOB_ID" "$START" "$$" > "$STAT_FILE" -bash "$SCRIPT" "$@" > "$LOG_FILE" 2>&1 +printf '\n── %s ────────────────────────────────────────────────\n' \ + "$(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE" + +bash "$SCRIPT" "$@" >> "$LOG_FILE" 2>&1 EC=$? END=$(date +%s) @@ -36,4 +40,10 @@ fi printf '{"id":"%s","status":"%s","start":%s,"end":%s,"exit":%s}\n' \ "$JOB_ID" "$STATUS" "$START" "$END" "$EC" > "$STAT_FILE" +# Trim to last LOG_MAX_LINES to prevent unbounded growth +line_count=$(wc -l < "$LOG_FILE" 2>/dev/null || echo 0) +if [ "$line_count" -gt "$LOG_MAX_LINES" ]; then + tail -n "$LOG_MAX_LINES" "$LOG_FILE" > "${LOG_FILE}.tmp" && mv "${LOG_FILE}.tmp" "$LOG_FILE" +fi + exit $EC