Sign in Home API docs Agent Sharing Privacy Support
Get Pling
iPhone app macOS agent (.dmg) Linux Windows GitHub

Home / Docs / Cron jobs

Push notifications for cron jobs

A cron job that fails silently is a backup you do not have. Add one curl line to your crontab and Pling pushes the result to your iPhone the moment a job finishes or fails. No agent required for this, just the Pling HTTP API and the curl you already have.

Ping when a job finishes (and when it fails)

The simplest form posts the message as the request body to /api/push/YOUR_TOKEN. Use && for success and || for failure:

0 3 * * * /usr/local/bin/backup.sh \
  && curl -sf https://api.plingpush.com/api/push/YOUR_TOKEN -d "Backup finished" \
  || curl -sf https://api.plingpush.com/api/push/YOUR_TOKEN -d "Backup FAILED"

Only alert on failure

If green runs should be silent, keep just the || branch and bump the priority:

30 2 * * * /usr/local/bin/db-dump.sh || \
  curl -sf -X POST https://api.plingpush.com/api/push \
    -H "Content-Type: application/json" \
    -d '{"token":"YOUR_TOKEN","title":"DB dump failed","message":"check db-dump.sh on web-01","priority":"high"}'

A reusable shell function

Drop this in a script you source, then call pling from anywhere. Set PLING_TOKEN at the top of the crontab so cron can see it:

pling() {
  curl -sf -X POST "https://api.plingpush.com/api/push" \
    -H "Content-Type: application/json" \
    -d "{\"token\":\"$PLING_TOKEN\",\"title\":\"$1\",\"message\":\"${2:-}\",\"priority\":\"${3:-normal}\"}" >/dev/null
}

# usage
long-running-job; pling "Job done" "exit $?"

One-liner with the GET form

For the most minimal setups you can pass everything as query parameters, no JSON or headers:

curl -s "https://api.plingpush.com/api/push/YOUR_TOKEN?title=Backup&message=done&priority=high"
Tip: running this on a server you also want to watch? The Pling host agent adds live CPU, memory, and disk metrics and lets you run scheduled commands remotely from the app.
Where to get your token: create an API token in the Pling app, or at plingpush.com/account. The full reference, including channels and priorities, is in the API docs.

Frequently asked

How do I get a push only when the cron job fails?

Chain the curl with ||: your-job || curl .... The shell only runs the part after || when the command exits non-zero, so you are pinged for failures and stay quiet on success.

Does this need the Pling host agent?

No. Sending a push is a plain HTTPS call, so any box with curl works. The host agent is separate and adds live metrics and remote scheduled commands, but it is not required just to send notifications.

Cron does not see my token. Why?

Cron runs with a minimal environment and does not load your shell profile. Set the token inside the crontab itself (PLING_TOKEN=... at the top) or read it from a file in the command, rather than relying on ~/.bashrc.

Does this work on macOS?

Yes. The same crontab line works on macOS. For jobs managed by launchd, call the same curl at the end of your script.

More recipes: GitHub Actions · Python · full API reference