pyclamav
is a Python utility script that uses the pyclamd
library to run ClamAV scans on specified folders and files that have been modified within a specified duration. This tool is configurable via a JSON configuration file and command-line arguments.
- Scan specified folders for viruses using ClamAV.
- Scan files modified within a specified duration (or all files if not specified).
- Configurable via a JSON configuration file.
- Command-line arguments for flexibility.
- Install ClamAV: Ensure that ClamAV is installed and running on your system.
- On Ubuntu/Debian
sudo apt install clamav clamav-daemon
sudo systemctl start clamav-daemon
sudo systemctl enable clamav-daemon
- CentOS/RHEL
sudo yum install clamav clamav-daemon
sudo systemctl start clamav-daemon
sudo systemctl enable clamav-daemon
You can add the following cronjob configuration:
0 2 * * * /usr/bin/freshclam
- Install the requirements
pip install -r requirements.txt
Create a JSON configuration file (e.g., config.json
) with the following structure:
{
"folders": ["/path/to/folder1", "/path/to/folder2"],
"log_file": "pyclamav.log",
"modified_file_since": "24h",
"verbose": false
}
folders
: List of folders to monitor.log_file
: Path to the log file.modified_file_since
: Duration for which files will be scanned (e.g.,24h
for 24 hours). If this value is not specified, all the files will be scannedverbose
: Verbose mode (true or false).
Run the pyclamav
script with the following command:
pyclamav --config config.json [--modified-since DURATION] [--verbose]
--config
: Path to the JSON configuration file. Default isconfig.json
.--modified-since
: Duration for which files will be scanned (e.g.,24h
for 24 hours,48h
for 48 hours). Default is24h
.--verbose
: Enable verbose mode. Default isFalse
.
A test data file is available in ./tests/data/
.
You can use the following config.json
file to test:
{
"folders" : ["./tests/data"],
"log_folder": "./logs/",
}
- Scan folders specified in the configuration file:
pyclamav --config config.json
- Scan folders and files modified in the last 7 days:
pyclamav --config config.json --modified-since 7d
- Scan folders and files modified in the last 1 hour with verbose mode:
pyclamav --config config.json --modified-since 1h --verbose
Add the following cronjob configuration to run it everyday
0 0 * * * /path/to/venv/bin/python3.11 /path/to/pyclamav/pyclamav.py -c /path/to/pyclamav/config.json
Logs are written to the user's home directory under the logs
folder. The log file is named pyclamav.log
.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or issues, please open an issue on the GitHub repository.