60 lines
1.5 KiB
Bash
60 lines
1.5 KiB
Bash
#!/bin/sh
|
|
|
|
MODE=${1:-"scan"}
|
|
|
|
scan() {
|
|
echo "Running ClamAV scan..."
|
|
SCAN_PRIORITY=${SCAN_PRIORITY:-low}
|
|
|
|
if [ "$SCAN_PRIORITY" = "low" ]; then
|
|
echo "Running scan in low priority mode."
|
|
nice -n 19 clamscan -r /scan --log=/var/log/clamav/clamav.log
|
|
else
|
|
echo "Running scan in full power mode."
|
|
clamscan -r /scan --log=/var/log/clamav/clamav.log
|
|
fi
|
|
}
|
|
|
|
report() {
|
|
echo "Generating report..."
|
|
local log_file="/var/log/clamav/clamav.log"
|
|
if [ ! -f "$log_file" ]; then
|
|
echo "No log file found."
|
|
return
|
|
fi
|
|
local total_files=$(grep "Infected files:" "$log_file" | cut -d" " -f3)
|
|
local infected_files=$(grep "Infected files:" "$log_file" | cut -d" " -f5)
|
|
local errors=$(grep "Total errors:" "$log_file" | cut -d" " -f3)
|
|
echo "Scan Report:"
|
|
echo "Total files scanned: $total_files"
|
|
echo "Infected files found: $infected_files"
|
|
echo "Errors during scan: $errors"
|
|
}
|
|
quarantine() {
|
|
echo "Quarantining infected files..."
|
|
local log_file="/var/log/clamav/clamav.log"
|
|
local quarantine_dir="/quarantine"
|
|
mkdir -p "$quarantine_dir"
|
|
grep "FOUND" "$log_file" | cut -d" " -f1 | while read -r infected_file; do
|
|
if [ -f "$infected_file" ]; then
|
|
mv "$infected_file" "$quarantine_dir/"
|
|
fi
|
|
done
|
|
}
|
|
|
|
case "$MODE" in
|
|
scan)
|
|
scan
|
|
;;
|
|
report)
|
|
report
|
|
;;
|
|
quarantine)
|
|
quarantine
|
|
;;
|
|
*)
|
|
echo "Unknown mode: $MODE"
|
|
exit 1
|
|
;;
|
|
esac
|