Skip to content

Instantly share code, notes, and snippets.

@asfaltboy
Last active October 26, 2017 10:00
Show Gist options
  • Save asfaltboy/23a7f963bbfcb48ce510307ec8cb8737 to your computer and use it in GitHub Desktop.
Save asfaltboy/23a7f963bbfcb48ce510307ec8cb8737 to your computer and use it in GitHub Desktop.
Log all cronjob output to syslog and send errors to sentry

Log cronjob output to syslog and send errors to sentry

The wonderful cron-sentry takes care of sending an event for program errors to sentry. To uniformy log everything outputted, we pipe both stderr and stdout to logger (should be available on most linux distros)

How to use

Download script, add execution perm and move to a directory on PATH

$ wget https://gist.githubusercontent.com/asfaltboy/23a7f963bbfcb48ce510307ec8cb8737/raw/49ebca20004211a16c85a61a77db7d0883ddf31c/log-and-sentry
$ chmod +x log-and-sentry
$ mv log-and-sentry

Crontab example

MAILTO=alert@yourcompany.com  # useful to debug errors with cron-sentry execution
SENTRY_DSN=<your dsn uri>     # to avoid repeating `cron-sentry --dsn`

@hourly log-and-sentry do_something arg -a arg2
#!/bin/bash
cron-sentry $@ 2>&1 | /bin/logger -t cronjob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment