add shell script for cronjob

This commit is contained in:
Arne Teuke
2025-06-08 15:33:03 +02:00
parent 44792d71c1
commit 38a51df380
4 changed files with 56 additions and 5 deletions

23
templates/scan.sh.erb Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Set paths
SCAN_DIR="<%= @cv_scan_dir %>"
LOG_FILE="<%= @cv_logfile %>"
TMP_ALERT="<%= @cv_alert_file %>"
EMAIL="<%= @cv_alert_email %>"
# Run clamscan
clamscan -r --infected --log="$LOG_FILE" "$SCAN_DIR" > /dev/null
# Check if infections were found
if grep -q "Infected files: [^0]" "$LOG_FILE"; then
echo "ClamAV has found infected files on $(hostname)!" > "$TMP_ALERT"
echo "" >> "$TMP_ALERT"
grep "FOUND" "$LOG_FILE" >> "$TMP_ALERT"
# Send the alert email
mail -s "⚠️ ClamAV Alert on $(hostname)" "$EMAIL" < "$TMP_ALERT"
fi
# Clean up
rm -f "$TMP_ALERT"