diff --git a/README.md b/README.md index b9a4dbb..bc26dcb 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,14 @@ The importer handles rotated logs in order from oldest to newest so entries are processed exactly once. If you rerun the script, it only ingests records with a timestamp newer than the latest one already stored in the database, preventing duplicates. + +## Cron Report Generation + +Use the `run-reports.sh` script to run all report intervals in one step. The script sets up the Python environment the same way as `run-import.sh`, making it convenient for automation via cron. + +```bash +./run-reports.sh +``` + +Running this script will create or update the hourly, daily, weekly and monthly reports under `output/`. + diff --git a/run-reports.sh b/run-reports.sh new file mode 100755 index 0000000..56f4c31 --- /dev/null +++ b/run-reports.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -e + +# Ensure virtual environment exists +if [ ! -d ".venv" ]; then + echo "[INFO] Creating virtual environment..." + python3 -m venv .venv + source .venv/bin/activate + echo "[INFO] Installing dependencies..." + pip install --upgrade pip + if [ -f requirements.txt ]; then + pip install -r requirements.txt + else + echo "[WARN] requirements.txt not found, skipping." + fi +else + echo "[INFO] Activating virtual environment..." + source .venv/bin/activate +fi + +# Generate all reports +echo "[INFO] Generating reports..." +python scripts/generate_reports.py hourly +python scripts/generate_reports.py daily +python scripts/generate_reports.py weekly +python scripts/generate_reports.py monthly + +# Deactivate to keep cron environment clean +if type deactivate >/dev/null 2>&1; then + deactivate +fi