ClamAV malware scanning, automatic security updates, and a terminal status dashboard for systemd Linux β built for EC2, tested on Ubuntu and Amazon Linux
Features β’ Quick Start β’ Usage β’ Contributing
| Feature | What it does | |
|---|---|---|
| π¦ | ClamAV scanning | Quick (30β90 s) or full (10β30 min) clamscan malware sweeps |
| π | Auto updates | Applies pending security updates during every scan (apt / dnf) |
| 𧬠| Fresh definitions | Runs freshclam before each scan and keeps the freshclam service healthy |
| π | Status dashboard | Terminal dashboard: last scan, infected count, services, virus DB, updates |
| β° | Scheduled scans | Installer drops a cron file β daily full scan at 02:00, health check every 6 h |
| π©Ί | Self-healing health check | Restarts dead services and refreshes stale virus definitions (> 7 days) |
| π¦ | One-command install | security-manager.sh install sets up packages, services, cron, and shell shortcuts |
| π | Logging | Everything logged under /var/log/security-monitor/, scan status as JSON |
| Requirement | Notes |
|---|---|
| Linux + systemd | Services are managed with systemctl |
| Bash 4.0+ | Both scripts are pure Bash |
| Root access | install, uninstall, health, and scan all need sudo |
| Internet access | To download ClamAV packages and virus definitions |
The installer validates the OS and supports:
- β
Ubuntu / Debian (
apt,unattended-upgrades) - β
Amazon Linux 2023 (
dnf,dnf-automatic)
Anything else exits with Unsupported operating system.
git clone https://github.com/CaputoDavide93/EC2-Linux-Security-Monitor.git
cd EC2-Linux-Security-Monitorchmod +x security-monitor.sh security-manager.shsudo ./security-manager.sh installThe installer:
- Installs ClamAV,
jq,curl, and the distro's auto-update tooling - Configures
freshclamand the ClamAV daemon - Enables automatic security updates (
unattended-upgrades/dnf-automatic) - Creates
/etc/cron.d/security-monitor(daily scan + 6-hourly health check) - Installs the monitor to
/usr/local/bin/security-monitor - Adds shell shortcuts:
security-status,security-scan,security-health
Then reload your shell to pick up the shortcuts:
source /etc/profile.d/security-monitor.shsudo security-monitor scan # quick scan (default)
security-monitor status # dashboardUsage: security-monitor [scan|status]
scan [quick|full] Run a security scan (default: quick)
status Show the status dashboard (default)
Every scan runs three steps:
- Update virus definitions β
freshclam(pausing the service to avoid lock conflicts) - Apply system updates β
apt-get upgradeordnf upgrade, security-focused - Scan for malware β
clamscan -r -i, excluding/sys,/proc,/dev,.git,node_modules,.cache
| Mode | Paths | Typical duration |
|---|---|---|
quick (default) |
/home /root (file-size and recursion limits) |
30β90 seconds |
full |
/home /root /opt /tmp /var /usr/local |
10β30 minutes |
Results are written to /var/lib/security-monitor/status.json and scan logs to
/var/log/security-monitor/scan-<timestamp>.log.
sudo security-monitor scan # quick scan
sudo security-monitor scan full # full scan
security-monitor status # dashboard (also the default with no args)The status dashboard shows: scan status and freshness, compliance indicator,
pending updates, ClamAV service state, virus database state, and quick actions.
Usage: security-manager.sh [install|uninstall|health]
install Install the security monitoring system
uninstall Remove the security monitoring system
health Perform a health check
Run without arguments for an interactive menu.
sudo ./security-manager.sh # interactive menu
sudo ./security-manager.sh install # non-interactive install
sudo ./security-manager.sh health # check & self-heal services, defs, cron
sudo ./security-manager.sh uninstall # remove (asks for confirmation)health verifies β and where possible repairs β the freshclam service, the
ClamAV daemon, virus-definition age (re-downloads if older than 7 days), the
cron file, and the installed scripts.
uninstall removes the cron jobs, installed scripts, shell shortcuts, data,
and logs. ClamAV packages stay installed; remove them separately with
apt-get remove --purge 'clamav*' or dnf remove 'clamav*'.
install creates /etc/cron.d/security-monitor for you:
# Daily full scan at 2:00 AM
0 2 * * * root /usr/local/bin/security-monitor scan full >/dev/null 2>&1
# Health check every 6 hours
0 */6 * * * root /usr/local/bin/security-manager health >/dev/null 2>&1Adjust the schedule by editing that file β the commands above are the only ones you need.
β Permission denied / "Root privileges required"
All commands except status need root:
sudo ./security-manager.sh install
sudo security-monitor scanβ "Freshclam had issues (may be in cooldown)"
ClamAV rate-limits definition downloads. The scan continues with the current database and freshclam retries automatically. Check progress with:
sudo tail /var/log/clamav/freshclam.logβ Dashboard says "No scan data available"
The dashboard reads /var/lib/security-monitor/status.json, which is created
by the first scan (and requires jq, installed by install):
sudo security-monitor scanβ "Unsupported operating system"
The installer only supports Ubuntu, Debian, and Amazon Linux (dnf). On other
distributions the package and service names differ, so install refuses to run.
There is no automated test suite. Before opening a PR, lint both scripts:
shellcheck security-monitor.sh security-manager.sh
bash -n security-monitor.sh && bash -n security-manager.shContributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License β see the LICENSE file for details.
β If this tool helped you, please give it a star! ββΒ·βMade with β€οΈ by Davide Caputo