Add cron-friendly report generation script

This commit is contained in:
Jordan Wages 2025-07-18 00:15:36 -05:00
commit e19138bc1a
2 changed files with 42 additions and 0 deletions

View file

@ -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/`.

31
run-reports.sh Executable file
View file

@ -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