CronNudge

Published October 21, 2026

Slack or Discord Alerts When a Cron Job Fails

Most cron failures are found by someone asking why yesterday's report is missing. Getting a message in the channel your team already reads is the fix. There are two ways to do it, and they catch different failures.

The first is in the job: when the script fails, it posts to a Slack or Discord incoming webhook. The second is from outside: the job pings a monitor when it finishes, and the monitor posts when the ping does not arrive. This page builds the first one properly, shows what it cannot see, and then covers the second. A job that never fires is crontab not running. The heartbeat pattern in general is how to monitor cron jobs.

Post from the job: the payloads

Both services give you a URL that accepts a JSON POST and posts it to one channel.

Slack incoming webhooks live at https://hooks.slack.com/services/.... You create one from a Slack app with Incoming Webhooks turned on, and pick the channel when you create it. The body needs a text field:

curl -fsS -m 10 -H 'Content-Type: application/json' \
  --data '{"text":"backup failed on db-1"}' \
  "$SLACK_WEBHOOK_URL"

Discord webhooks live at https://discord.com/api/webhooks/<id>/<token>. You create one under a channel's Integrations settings. The body needs a content field, which Discord limits to 2,000 characters:

curl -fsS -m 10 -H 'Content-Type: application/json' \
  --data '{"content":"backup failed on db-1"}' \
  "$DISCORD_WEBHOOK_URL"

Treat both URLs as secrets. Anyone with the URL can post to the channel. Keep them in an environment file readable only by the job's user, not in the crontab or the repository. How cron loads that file is in cron job environment variables.

Build the JSON with jq

A message that includes an error line will eventually include a quote, a backslash, or a newline, and hand-built JSON breaks on all three. jq escapes it:

msg="backup failed on $(hostname): $(tail -n 1 /var/log/backup.log)"
jq -n --arg text "$msg" '{text: $text}' |
  curl -fsS -m 10 -H 'Content-Type: application/json' --data @- "$SLACK_WEBHOOK_URL"

For Discord, use '{content: $text}'.

Wire it to the exit code

In the crontab line

0 3 * * * . /etc/backup.env; /usr/local/bin/backup.sh || /usr/local/bin/notify "backup exited $?"

$? inside the || branch is still the exit code of backup.sh. /usr/local/bin/notify is a small script that wraps the jq and curl lines above. Cron runs the line with /bin/sh, so keep it POSIX, and remember that % is special in a crontab line.

In a bash script, with a trap

A trap on EXIT runs however the script ends, including when set -e stops it early:

#!/usr/bin/env bash
set -euo pipefail

notify() {
  jq -n --arg text "$1" '{text: $text}' |
    curl -fsS -m 10 -H 'Content-Type: application/json' --data @- "$SLACK_WEBHOOK_URL" > /dev/null
}

trap 'status=$?; if [ "$status" -ne 0 ]; then notify "backup failed on $(hostname), exit $status" || true; fi; exit "$status"' EXIT

pg_dump mydb | gzip > /backups/mydb.sql.gz

set -o pipefail makes a failed pg_dump fail the pipeline instead of gzip's success hiding it. || true keeps a failed notification from changing the exit code, and exit "$status" returns the job's own code to cron.

What the in-job alert cannot see

The alert above is code inside the job. It only runs when the job runs, on a machine that is up, far enough to reach the trap. It stays silent when:

  • The job never starts. The cron daemon is stopped, the crontab was overwritten by a deploy, the schedule is wrong, or the host was rebuilt without it.
  • The host is down. No process, no trap, no curl.
  • The job hangs. A stuck pg_dump or a network call with no timeout never exits, so the trap never fires.
  • It fails kill -9. SIGKILL, including the kernel's out-of-memory killer, ends the process without running any trap.
  • The webhook call fails. A rotated URL or a network problem at 3 AM loses the only alert, usually unnoticed.

There is also noise in the other direction. A job every five minutes that keeps failing posts every five minutes until someone fixes it or mutes the channel.

Alert from outside with a heartbeat

A heartbeat check flips the logic. The job pings a URL when it finishes. The monitor knows the schedule, and if the ping is late it posts to Slack or Discord itself. A job that never started, a dead host, and a hang all look the same from outside: no ping by the deadline.

#!/usr/bin/env bash
set -uo pipefail
PING_URL="https://cronnudge.com/ping/<check-id>"

/usr/local/bin/backup.sh
status=$?
curl -fsS -m 10 --retry 3 "$PING_URL?exit=$status" > /dev/null
exit "$status"

A non-zero ?exit= on the success URL is a failure. $PING_URL/fail is the same thing from an error path. Both alert right away instead of waiting for the deadline. Silence after the grace period is the alert for everything else. Build and check the schedule with the cron expression tool.

Slack and Discord alerts in CronNudge

In the app, open Alerts or Integrations and add a channel by pasting an incoming webhook. CronNudge checks the URL before saving it: a Slack channel must be an https://hooks.slack.com/ URL, and a Discord channel must be an https://discord.com/api/webhooks/ or discordapp.com webhook URL.

What arrives:

  • Down. When no successful ping arrives by the deadline, or a failure ping arrives, the check goes down and every enabled channel in the project gets one alert. Slack gets a text message, such as CronNudge: nightly-backup is down. with a link to the check. Discord gets a message with an embed that has the title, a short description, the project and check names, a link, and the time.
  • Recovery. The next successful ping sends one recovery message.
  • Nothing in between. A check that stays down does not post again on every missed run. More failure pings while it is down do not send more alerts.

If Slack or Discord returns a rate limit or a server error, CronNudge retries the delivery, up to three attempts in total.

To try a channel without breaking anything, open a check and use Send test alert. It posts a message marked [TEST] to the project's enabled channels and does not change the check's status or history. You can send five test alerts an hour.

With run tracking on, the same channels also get alerts for a run that is stuck past its max runtime, a second start while a run is open, and a duration far from recent runs. Those signals are in assertions, runs, and agents.

Plan limits

Free includes email plus one Slack or Discord channel, 10 checks, and a 5-minute minimum interval. Pro is $12 a month for 100 checks, a 1-minute minimum, unlimited Slack and Discord channels, and signed generic webhooks for anything else, such as an incident tool. See pricing.

FAQ

How do I send a Slack message when a cron job fails? Create a Slack incoming webhook, then POST JSON with a text field to it from the failure path, for example backup.sh || notify. Build the JSON with jq so quotes and newlines in the message do not break it.

What is the Discord webhook payload for a cron alert? POST JSON with a content field to the https://discord.com/api/webhooks/ URL. Discord limits content to 2,000 characters.

Why didn't my Slack alert fire when the cron job didn't run? The alert code lives inside the job. If cron never started it, the host was down, or the process was killed with SIGKILL, nothing ran to send it. A heartbeat check alerts from outside when the finish ping is missing.

How do I stop a failing cron job from spamming the channel? In-job alerts post on every failed run. A monitor that tracks state sends one alert when the check goes down and one when it recovers. CronNudge works that way.

Can I test the Slack or Discord channel without failing the job? In CronNudge, open a check and use Send test alert. It posts a message marked [TEST] and does not change the check. For a DIY webhook, run the curl command by hand.

Is Slack or Discord alerting free in CronNudge? Free includes email plus one Slack or Discord channel. Pro, at $12 a month, has unlimited Slack and Discord channels and adds signed webhooks.


An alert inside the job tells you it failed. An alert from outside also tells you it never ran. Create the check, or read where cron logs live to see what the failed run printed. Related: prevent overlapping cron jobs, monitor database backup cron jobs, and n8n.