Monitor Python Scripts Run by Cron
A plain Python script triggered by system cron — no Django, no Celery, just a script and a crontab entry — is one of the most common scheduled-job patterns, and one of the easiest to monitor.
Setup
Create an incoming monitor
Add a heartbeat monitor in Pingtastic with a grace period past the script's schedule interval.
Ping at the end of the script
Add the ping call after the real work succeeds.
import requests
def main():
# ...existing script logic...
requests.get('https://ping.pingtastic.net/ping/nightly-export', timeout=5)
if __name__ == '__main__':
main()Schedule it with system cron
Use the full path to your virtualenv's Python interpreter.
0 2 * * * /opt/myapp/venv/bin/python /opt/myapp/scripts/nightly_export.pyGotchas
- ⚠Cron runs with a minimal environment — a script that works fine run manually can fail under cron because of a missing PATH entry, unset env var, or relative-path assumption. Use absolute paths everywhere in the crontab line.
- ⚠An unhandled exception midway through the script means execution never reaches the ping call — correct behavior, but wrap the real work in try/except if you also want to log the failure locally.
Questions
Do I need a scheduling library for this, or is cron enough?
For a single script on a fixed schedule, plain system cron plus a ping at the end is the simplest reliable setup — no extra dependency needed.
What if the script is scheduled with APScheduler instead of system cron?
The ping placement is the same (at the end of the job function), but the process itself needs to stay running continuously for APScheduler's in-process scheduling to fire — if the process dies, nothing fires and nothing logs it, which a heartbeat ping still correctly catches as a missed check-in.
Related guides
Start monitoring your Python cron script
Set up your first monitor in under five minutes.
Get started — $5/month