From 758360023b559fdf5190b96d5f52d2f23a17d87f Mon Sep 17 00:00:00 2001 From: Marco Cadetg Date: Thu, 12 Jun 2025 16:50:15 +0200 Subject: [PATCH] improve clear old logs --- scripts/clear_old_logs.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/clear_old_logs.sh b/scripts/clear_old_logs.sh index eb3c98f..28ef6c0 100755 --- a/scripts/clear_old_logs.sh +++ b/scripts/clear_old_logs.sh @@ -39,8 +39,15 @@ if [ -n "$files_to_delete" ]; then echo " - $file_to_delete" done # Actual deletion - echo "$files_to_delete" | xargs -d '\n' rm -f - + for file_to_delete in $files_to_delete; do + # Check if the file exists before trying to delete it + if [ -e "$file_to_delete" ]; then + rm -f "$file_to_delete" + else + echo "Warning: File '$file_to_delete' does not exist." + fi + done + # Count how many were actually passed to xargs (can be tricky if names have newlines) # A simpler way is to count lines from the `files_to_delete` variable num_deleted=$(echo "$files_to_delete" | wc -l)