Compare commits
1 Commits
0d26003492
...
ce83e4bbab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce83e4bbab |
@@ -1,26 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
|
# Set paths
|
||||||
SCAN_DIR="<%= @cv_scan_dir %>"
|
SCAN_DIR="<%= @cv_scan_dir %>"
|
||||||
LOG_FILE="<%= @cv_logfile %>"
|
LOG_FILE="<%= @cv_logfile %>"
|
||||||
TMP_ALERT="<%= @cv_alert_file %>"
|
TMP_ALERT="<%= @cv_alert_file %>"
|
||||||
EMAIL="<%= @cv_alert_email %>"
|
EMAIL="<%= @cv_alert_email %>"
|
||||||
|
|
||||||
# Ensure the log directory exists
|
# Run clamscan
|
||||||
mkdir -p "$(dirname "$LOG_FILE")"
|
clamscan -r --infected --log="$LOG_FILE" "$SCAN_DIR" > /dev/null
|
||||||
|
|
||||||
# Preferred: clamdscan with multiscan + fdpass
|
# Check if infections were found
|
||||||
clamdscan --multiscan --fdpass --infected --log="$LOG_FILE" "$SCAN_DIR" > /dev/null || true
|
if grep -q "Infected files: [^0]" "$LOG_FILE"; then
|
||||||
|
echo "ClamAV has found infected files on $(hostname)!" > "$TMP_ALERT"
|
||||||
# Check for infections (same logic as before)
|
echo "" >> "$TMP_ALERT"
|
||||||
if grep -q "Infected files: [^0]" "$LOG_FILE" 2>/dev/null; then
|
grep "FOUND" "$LOG_FILE" >> "$TMP_ALERT"
|
||||||
{
|
|
||||||
echo "ClamAV has found infected files on $(hostname)!"
|
|
||||||
echo ""
|
|
||||||
grep "FOUND" "$LOG_FILE" || true
|
|
||||||
} > "$TMP_ALERT"
|
|
||||||
|
|
||||||
|
# Send the alert email
|
||||||
mail -s "⚠️ ClamAV Alert on $(hostname)" "$EMAIL" < "$TMP_ALERT"
|
mail -s "⚠️ ClamAV Alert on $(hostname)" "$EMAIL" < "$TMP_ALERT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$TMP_ALERT"
|
# Clean up
|
||||||
|
rm -f "$TMP_ALERT"
|
||||||
|
|||||||
Reference in New Issue
Block a user