A collection of setup and utility scripts for Ubuntu systems.
A comprehensive malware scanning utility that installs and manages multiple antivirus engines on Ubuntu systems. It supports both ClamAV and Maldet (Linux Malware Detector) with flexible command-line options to run them individually or together.
-
Dual-Engine Support
- ClamAV (antivirus engine) - installed via apt
- Maldet (Linux Malware Detector) - installed from official GitHub repository
-
Selective Scanning - Run individual engines or both via command-line flags
-
Automatic Signature Updates - Both tools update definitions before every scan
-
Color-Coded Output - Clear visual indicators for scan results
-
Comprehensive Logging - All scan results saved to
/var/log/malscan/ -
Flexible Directory Targeting - Scan any directory on the system
- Ubuntu/Debian Linux system
- Root or sudo privileges
- Internet connection (for signature updates and Maldet installation)
- Disk space for tool installation and logging
- Clone or download the script:
git clone https://github.com/commandrine/ubuntu-setup-scripts.git
cd ubuntu-setup-scripts- Make the script executable:
chmod +x malscan.shsudo bash malscan.sh [OPTIONS] [scan_directory]| Option | Description |
|---|---|
-c, --clamav |
Run ClamAV scan only |
-m, --maldet |
Run Maldet scan only |
-a, --all |
Run both ClamAV and Maldet scans (default) |
-h, --help |
Display help message |
| Argument | Description | Default |
|---|---|---|
scan_directory |
Directory path to scan | /home |
Scan /home with all engines (default):
sudo bash malscan.sh /homeScan /home with ClamAV only:
sudo bash malscan.sh -c /homeScan /var/www with Maldet only:
sudo bash malscan.sh -m /var/wwwScan entire filesystem with both engines:
sudo bash malscan.sh -a /Use long-form flags (ClamAV only):
sudo bash malscan.sh --clamav /homeDisplay help:
sudo bash malscan.sh -h- System Preparation - Updates package lists and installs required dependencies
- Engine Installation - Installs only the requested scanning engines:
- ClamAV via apt package manager
- Maldet from official GitHub repository (rfxn/linux-malware-detect)
- Signature Updates - Downloads latest malware definitions before scanning
- Scanning Phase - Recursively scans the target directory with enabled engines
- Results Processing - Color-codes and displays findings with human-readable formatting
- Review Summary - Provides next steps for threat handling and quarantine options
Scan Results Display:
- ✓ Green checkmark indicates clean scans (no threats detected)
- ⚠ Red warning symbol indicates detections requiring review
- Summary statistics (files scanned, malware hits, data scanned)
- Detailed threat listings with file paths
Log Files Location:
All scan logs are saved to /var/log/malscan/:
clamav_scan_YYYYMMDD_HHMMSS.log- ClamAV scan resultsmaldet_scan_YYYYMMDD_HHMMSS.log- Maldet scan resultsmaldet_update_ver_YYYYMMDD_HHMMSS.log- Maldet version updatesmaldet_update_sigs_YYYYMMDD_HHMMSS.log- Maldet signature updatesmaldet_clone.log- Maldet repository clone logmaldet_install.log- Maldet installation log
View Maldet Reports:
sudo maldet --report list
sudo maldet --report <report-id>Quarantine Suspicious Files:
sudo maldet --quarantine <report-id>View Maldet Scan Details:
cat /usr/local/maldetect/sess/*ClamAV Quarantine Location:
ls -la /var/lib/clamav/Weekly scan of /home with ClamAV only (every Sunday at 2 AM):
0 2 * * 0 root /usr/bin/bash /path/to/malscan.sh -c /home >> /var/log/malscan/cron.log 2>&1Daily Maldet-only scan of /var/www (every day at 3 AM):
0 3 * * * root /usr/bin/bash /path/to/malscan.sh -m /var/www >> /var/log/malscan/cron.log 2>&1Monthly full system scan with both engines (first day at 4 AM):
0 4 1 * * root /usr/bin/bash /path/to/malscan.sh -a / >> /var/log/malscan/cron.log 2>&1Script fails with "must be run as root":
- Ensure you're using
sudo bash malscan.sh ... - Do not try to run with
bash sudo malscan.sh(incorrect order)
Maldet installation fails:
- Check internet connection for GitHub access
- Verify
/tmphas sufficient free space - Review
/var/log/malscan/maldet_clone.logand/var/log/malscan/maldet_install.log - If only Maldet is requested (-m flag), the script will exit with an error
ClamAV installation fails:
- Ensure apt repositories are configured correctly
- Run
sudo apt-get updatebefore executing the script - Check disk space for signature database downloads
Scan takes too long:
- Large directories with many files take proportionally longer
- Consider scanning specific subdirectories instead of root (/)
- Monitor disk I/O and system load with
toporiotop
Permission denied errors during scanning:
- Some directories require root access to scan
- The script must be run with
sudofor full system access - Some files may be locked by running processes (this is normal and won't cause errors)
- ClamAV Documentation: https://www.clamav.net/
- Maldet Repository: https://github.com/rfxn/linux-malware-detect
- ClamAV Package: https://packages.ubuntu.com/search?keywords=clamav
- First Run: Takes longer due to engine installations and initial signature downloads
- Large Directories: Scanning
/or other large directories may take 30+ minutes - System Impact: Heavy I/O usage during scanning; consider running during off-peak hours
- Signature Updates: Each scan updates signatures, adding 1-2 minutes to execution time
- Disk Space: Ensure adequate space for logs in
/var/log/malscan/
These scripts are provided as-is for Ubuntu system administration.
Execute the specific scripts from Terminal.