Logging nach 7 Tagen entfernt

This commit is contained in:
2025-06-18 14:53:33 +02:00
parent 2e6e8c350f
commit 4272f5bc24

View File

@@ -80,6 +80,18 @@ show_menu() {
}
main() {
# Alte Logeinträge aus der Logdatei entfernen (basierend auf konfigurierbarem Zeitraum)
LOG_RETENTION_DAYS=7
tmp_log="${LOG_FILE}.tmp"
cutoff_date=$(date -d "${LOG_RETENTION_DAYS} days ago" +'%Y-%m-%d %H:%M:%S')
awk -v cutoff="$cutoff_date" '
match($0, /^\[[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\]/) {
timestamp = substr($0, 2, 19)
if (timestamp >= cutoff) print $0
}
' "$LOG_FILE" > "$tmp_log" && mv "$tmp_log" "$LOG_FILE"
# Alte Logeinträge löschen, wenn älter als 7 Tage
find . -name "$LOG_FILE" -type f -mtime +7 -exec rm {} \;
log "Skript gestartet."
download_file
extract_data