Fix ClamAV progress display to only update on file change

Problem:
Progress display updated every 0.2s showing same filename repeatedly:
  Scanning... ⠹ | Last file: pickledperil.com-Dec-2025.gz | Elapsed: 1m
  Scanning... ⠸ | Last file: pickledperil.com-Dec-2025.gz | Elapsed: 1m
  Scanning... ⠼ | Last file: pickledperil.com-Dec-2025.gz | Elapsed: 1m

This created spam and made it hard to see actual progress.

Solution:
Track last displayed filename and only update when it changes:
- Added last_filename variable
- Only printf when filename != last_filename
- Removed spinner animation (unnecessary with file tracking)
- Changed format to simpler: "Scanning: [filename] | Elapsed: [time]"

Now displays:
  Scanning: pickledperil.com-Dec-2025.gz | Elapsed: 1m
  Scanning: awstats122025.pickledperil.com.txt | Elapsed: 1m 5s
  Scanning: error.log | Elapsed: 1m 10s

Each line shows a new file being scanned, no repetition.
This commit is contained in:
cschantz
2025-12-23 16:59:46 -05:00
parent 50001c2e4a
commit 56879cadb5
+9 -11
View File
@@ -967,8 +967,7 @@ for scanner in "${AVAILABLE_SCANNERS[@]}"; do
# Monitor activity by watching log file growth # Monitor activity by watching log file growth
last_size=0 last_size=0
spin_chars='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏' last_filename=""
spin_index=0
stall_counter=0 stall_counter=0
while kill -0 $CLAM_PID 2>/dev/null; do while kill -0 $CLAM_PID 2>/dev/null; do
@@ -980,14 +979,14 @@ for scanner in "${AVAILABLE_SCANNERS[@]}"; do
current_file=$(tail -1 "$LOG_DIR/clamav.log" 2>/dev/null | grep -o '/[^:]*' | head -1) current_file=$(tail -1 "$LOG_DIR/clamav.log" 2>/dev/null | grep -o '/[^:]*' | head -1)
if [ -n "$current_file" ]; then if [ -n "$current_file" ]; then
filename=$(basename "$current_file" 2>/dev/null || echo "...") filename=$(basename "$current_file" 2>/dev/null || echo "...")
elapsed=$(($(date +%s) - SCAN_START))
spin_char="${spin_chars:$spin_index:1}" # Only update display when filename changes
printf "\r Scanning... %s | Last file: %s | Elapsed: %s " \ if [ "$filename" != "$last_filename" ]; then
"$spin_char" "${filename:0:40}" "$(format_time $elapsed)" elapsed=$(($(date +%s) - SCAN_START))
else printf "\r Scanning: %s | Elapsed: %s " \
elapsed=$(($(date +%s) - SCAN_START)) "${filename:0:50}" "$(format_time $elapsed)"
spin_char="${spin_chars:$spin_index:1}" last_filename="$filename"
printf "\r Scanning... %s | Elapsed: %s " "$spin_char" "$(format_time $elapsed)" fi
fi fi
# Check for stalled scan (no log growth in 60 seconds) # Check for stalled scan (no log growth in 60 seconds)
@@ -1002,7 +1001,6 @@ for scanner in "${AVAILABLE_SCANNERS[@]}"; do
last_size=$current_size last_size=$current_size
fi fi
spin_index=$(( (spin_index + 1) % 10 ))
sleep 0.2 sleep 0.2
done done