diff options
| -rwxr-xr-x | dotfiles/common/.local/bin/cron/log-cleanup | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/dotfiles/common/.local/bin/cron/log-cleanup b/dotfiles/common/.local/bin/cron/log-cleanup index e8d6ac4..b2d1fbb 100755 --- a/dotfiles/common/.local/bin/cron/log-cleanup +++ b/dotfiles/common/.local/bin/cron/log-cleanup @@ -19,8 +19,15 @@ cutoff=$(date -d "$DAYS days ago" +%Y%m%d) for f in "$LOG_DIR"/*.log; do [ -f "$f" ] || continue - # Extract YYYY-MM-DD from filename; skip files without a date - filedate=$(basename "$f" | grep -oP '\d{4}-\d{2}-\d{2}' | head -1) + # Extract YYYY-MM-DD from filename, or fall back to an embedded + # _<10-digit-epoch>_ (used by hyprland-runtime logs which lack a + # human-readable date in the filename). Skip files with neither. + name=$(basename "$f") + filedate=$(echo "$name" | grep -oP '\d{4}-\d{2}-\d{2}' | head -1) + if [ -z "$filedate" ]; then + epoch=$(echo "$name" | grep -oP '_\K[0-9]{10}(?=_)' | head -1) + [ -n "$epoch" ] && filedate=$(date -d "@$epoch" +%Y-%m-%d 2>/dev/null) + fi [ -n "$filedate" ] || continue # Skip files still being written to (modified in the last 24h). # This prevents deleting active logs from long-running sessions. |
