Six‑Line Bash Script for Daily Email Digests
Deploy the script to `/opt/scripts/digest.sh`, set up a cron job, and ensure the Nylas CLI is installed and authenticated.
Deploy the script to `/opt/scripts/digest.sh`, set up cron entry, ensure Nylas CLI is installed and authenticated, and test sending
Summary
The article presents a concise bash script that queries a PostgreSQL database for signups, errors, and revenue, then sends a daily digest email using the Nylas CLI. The script sets `-euo pipefail`, queries the database with `psql -tA -h db.example.com -U readonly app -c "SELECT …"`, and constructs the email body with newline separators. It includes a cron entry that runs the script at 7 AM Monday‑Friday as the `ops` user. The article compares this approach to alternatives such as Looker, Zapier, and internal reporting services, highlighting cost and flexibility advantages. It also provides optional enhancements: HTML body, sparklines, CSV attachment, and skipping weekends via a holidays file. The article notes that cron runs with a minimal PATH, so the Nylas binary must be in a system‑wide location or the PATH must be set in the script.
Key changes
- 6‑line bash script queries Postgres and sends email via CLI
- Cron entry runs at 7 AM Mon‑Fri as `ops` user
- Optional HTML body, sparklines, CSV attachment
- Skips weekends using a holidays file
- Cron PATH issue: binary must be system‑wide or PATH set
- Comparison: cheaper than Looker/Zapier, no engineering time
- Uses `nylas email send` with `--subject` and `--body`
- Can be extended with `--html` and `--attachment`