Enhance mailtrace script: add support for specifying a single log file and improve error handling for log file options
This commit is contained in:
+15
-4
@@ -73,6 +73,7 @@ set -euo pipefail
|
|||||||
|
|
||||||
FOLLOW=0
|
FOLLOW=0
|
||||||
ALL_LOGS=0
|
ALL_LOGS=0
|
||||||
|
LOG_FILE=""
|
||||||
|
|
||||||
FAIL_ONLY=0
|
FAIL_ONLY=0
|
||||||
SUCCESS_ONLY=0
|
SUCCESS_ONLY=0
|
||||||
@@ -140,6 +141,7 @@ Debug:
|
|||||||
Input / Zeitraum:
|
Input / Zeitraum:
|
||||||
--follow tail -F /var/log/mail.log (live)
|
--follow tail -F /var/log/mail.log (live)
|
||||||
--all-logs /var/log/mail.log* inkl. .gz (historisch)
|
--all-logs /var/log/mail.log* inkl. .gz (historisch)
|
||||||
|
--log-file <pfad> einzelne Logdatei (auch .gz); nicht kombinierbar mit --follow/--all-logs
|
||||||
--since <prefix> Timestamp prefix-match (z.B. 2026-01-13T14:47)
|
--since <prefix> Timestamp prefix-match (z.B. 2026-01-13T14:47)
|
||||||
--until <prefix> stoppe sobald ts >= prefix (ISO8601 string compare)
|
--until <prefix> stoppe sobald ts >= prefix (ISO8601 string compare)
|
||||||
USAGE
|
USAGE
|
||||||
@@ -150,6 +152,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
--follow) FOLLOW=1 ;;
|
--follow) FOLLOW=1 ;;
|
||||||
--all-logs) ALL_LOGS=1 ;;
|
--all-logs) ALL_LOGS=1 ;;
|
||||||
|
--log-file) LOG_FILE="${2:-}"; shift ;;
|
||||||
--success) SUCCESS_ONLY=1 ;;
|
--success) SUCCESS_ONLY=1 ;;
|
||||||
--fail) FAIL_ONLY=1 ;;
|
--fail) FAIL_ONLY=1 ;;
|
||||||
--addr) ADDR_FILTER="${2:-}"; shift ;;
|
--addr) ADDR_FILTER="${2:-}"; shift ;;
|
||||||
@@ -185,6 +188,14 @@ if [[ "$DEDUP_PREFER" != "final" && "$DEDUP_PREFER" != "amavis" && "$DEDUP_PREFE
|
|||||||
echo "Ungültiges --dedup-prefer: $DEDUP_PREFER (final|amavis|first|last)" >&2
|
echo "Ungültiges --dedup-prefer: $DEDUP_PREFER (final|amavis|first|last)" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "$LOG_FILE" && ($FOLLOW -eq 1 || $ALL_LOGS -eq 1) ]]; then
|
||||||
|
echo "--log-file kann nicht zusammen mit --follow oder --all-logs verwendet werden." >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
if [[ -n "$LOG_FILE" && ! -r "$LOG_FILE" ]]; then
|
||||||
|
echo "Datei nicht lesbar: $LOG_FILE" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
if [[ $SUCCESS_ONLY -eq 1 && $FAIL_ONLY -eq 1 ]]; then
|
if [[ $SUCCESS_ONLY -eq 1 && $FAIL_ONLY -eq 1 ]]; then
|
||||||
echo "Bitte nur eines von --success oder --fail verwenden." >&2
|
echo "Bitte nur eines von --success oder --fail verwenden." >&2
|
||||||
exit 2
|
exit 2
|
||||||
@@ -201,12 +212,12 @@ fi
|
|||||||
# --- Input selection ---------------------------------------------------------
|
# --- Input selection ---------------------------------------------------------
|
||||||
if [[ $FOLLOW -eq 1 ]]; then
|
if [[ $FOLLOW -eq 1 ]]; then
|
||||||
INPUT_CMD=(sudo tail -F /var/log/mail.log)
|
INPUT_CMD=(sudo tail -F /var/log/mail.log)
|
||||||
else
|
elif [[ -n "$LOG_FILE" ]]; then
|
||||||
if [[ $ALL_LOGS -eq 1 ]]; then
|
INPUT_CMD=(sudo zcat -f "$LOG_FILE")
|
||||||
|
elif [[ $ALL_LOGS -eq 1 ]]; then
|
||||||
INPUT_CMD=(sudo zcat -f /var/log/mail.log*)
|
INPUT_CMD=(sudo zcat -f /var/log/mail.log*)
|
||||||
else
|
else
|
||||||
INPUT_CMD=(sudo cat /var/log/mail.log)
|
INPUT_CMD=(sudo cat /var/log/mail.log)
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user