← Back to blog
·5 min read

How to Get Cron Job Alerts in Slack

Your cron jobs run on a server. Your team lives in Slack. Here's how to connect the two so you get instant alerts when a job fails, runs late, or overlaps.

What you'll build

By the end of this guide, you'll have:

  • A CronSafe monitor tracking your cron job's heartbeat
  • Slack alerts when the job misses its schedule
  • Job output included in the alert message
  • Escalating reminders if the issue isn't resolved

Total setup time: about 5 minutes.

Step 1: Create a CronSafe monitor

Sign up at getcronsafe.com and create a new monitor:

  • Name: prod-backup (or whatever describes your job)
  • Schedule: Match your crontab (e.g., 0 for hourly)
  • Grace period: 10 minutes (adjust based on your job's typical duration)

You'll get a ping URL like:

https://api.getcronsafe.com/ping/a1b2c3d4

Step 2: Add the ping to your cron job

Add a curl to the end of your script:

bash
#!/bin/bash
set -euo pipefail

# Your job logic
pg_dump mydb > /backups/mydb_$(date +%Y%m%d_%H%M).sql
aws s3 cp /backups/mydb_$(date +%Y%m%d_%H%M).sql s3://my-bucket/

# Ping CronSafe on success
curl -s -X POST https://api.getcronsafe.com/ping/a1b2c3d4 \
  -d "Backup completed: $(du -h /backups/mydb_$(date +%Y%m%d_%H%M).sql | cut -f1)"

The -d flag sends the job output with the ping. This output will appear in your Slack alert, so you can see at a glance what happened.

Step 3: Connect Slack to CronSafe

In CronSafe, go to your monitor's alert settings and add Slack as an alert channel. You have two options:

Option A: Slack webhook (recommended)

1. Go to api.slack.com/apps and create a new app 2. Enable Incoming Webhooks 3. Add a webhook to your #ops-alerts channel 4. Copy the webhook URL (looks like https://hooks.slack.com/services/T.../B.../xxx) 5. Paste it into CronSafe's Slack webhook field

Option B: CronSafe Slack integration

Click "Connect Slack" in CronSafe's alert settings. This uses OAuth and lets you pick the channel directly from a dropdown. No webhook setup needed.

Step 4: Test the integration

Trigger a test alert from CronSafe's dashboard to verify the Slack message arrives. You should see something like:

🔴 CronSafe Alert: prod-backup is DOWN
Monitor "prod-backup" missed its expected ping.
Schedule: every hour
Last ping: 2 hours ago
Grace period: 10 minutes

→ View monitor: https://www.getcronsafe.com/dashboard

Step 5: Add fail pings for faster alerts

Instead of waiting for a missed ping (which requires the grace period to expire), you can send an explicit fail ping when your job errors:

bash
#!/bin/bash
set -euo pipefail

MONITOR_URL="https://api.getcronsafe.com/ping/a1b2c3d4"

# Trap errors and send fail ping
cleanup() {
  local exit_code=$?
  if [ $exit_code -ne 0 ]; then
    curl -s -X POST "${MONITOR_URL}/fail" \
      -d "Exit code: $exit_code"
  fi
}
trap cleanup EXIT

# Signal start
curl -s "${MONITOR_URL}/start"

# Your job
OUTPUT=$(pg_dump mydb 2>&1)
echo "$OUTPUT" > /backups/mydb_$(date +%Y%m%d_%H%M).sql

# Signal success with output
curl -s -X POST "$MONITOR_URL" -d "$OUTPUT"

This gives you three signals in Slack:

  • Start: Job began (useful for tracking duration)
  • Success: Job completed with output
  • Fail: Job crashed with error details

Complete working example

Here's a production-ready backup script with full Slack alerting:

bash
#!/bin/bash
set -euo pipefail

MONITOR="https://api.getcronsafe.com/ping/a1b2c3d4"
BACKUP_DIR="/backups"
DB_NAME="mydb"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${DB_NAME}_${TIMESTAMP}.dump"

# Send fail ping on any error
trap 'curl -s -X POST ${MONITOR}/fail -d "Backup failed at $(date)"' ERR

# Signal start
curl -s "${MONITOR}/start"

# Create backup
pg_dump -Fc "$DB_NAME" > "$BACKUP_FILE"

# Validate size (must be > 1MB)
SIZE=$(stat --printf="%s" "$BACKUP_FILE")
if [ "$SIZE" -lt 1048576 ]; then
  echo "Backup suspiciously small: $SIZE bytes"
  exit 1
fi

# Upload to S3
aws s3 cp "$BACKUP_FILE" "s3://my-bucket/backups/"

# Cleanup old local backups (keep 7 days)
find "$BACKUP_DIR" -name "${DB_NAME}_*.dump" -mtime +7 -delete

# Signal success
HUMAN_SIZE=$(numfmt --to=iec "$SIZE")
curl -s -X POST "$MONITOR" \
  -d "Backup OK: ${HUMAN_SIZE}, uploaded to s3://my-bucket/backups/"

When this runs successfully, you'll see in Slack:

✅ CronSafe: prod-backup is UP
Output: Backup OK: 45M, uploaded to s3://my-bucket/backups/

When it fails:

🔴 CronSafe Alert: prod-backup FAILED
Output: Backup failed at Mon Mar 25 03:00:01 UTC 2026

Adding Discord and Telegram

CronSafe also supports Discord webhooks, Telegram bots, and generic webhooks. You can add multiple channels to the same monitor — for example, Slack for the team and email as a backup.

On the Pro plan, you get escalating reminders that re-alert at 1 hour, 6 hours, and 24 hours. This ensures critical failures don't get buried in a busy Slack channel.

Start monitoring your cron jobs for free

20 monitors, email alerts, GitHub badges. No credit card required.

Get started free →