# The instant a cron job fails.

> Get a push when a cron job or scheduled task fails. Add one line to your crontab or systemd timer and failure alerts reach your phone in under a second.

<!-- source: https://pocketalert.app/use-cases/cron-job-alerts -->

Pocket Alert sends a push notification to your phone the moment a cron job fails. Chain one line onto any scheduled command with && or || — fire on failure, on success, or both, and the push arrives as the job exits, error output included.

## Three steps to cron failure alerts

1. **Get your URL or CLI** — Copy the incoming webhook URL for your application, or install the Pocket Alert CLI.
2. **Add one line** — Chain a curl call or pocketalert send onto your cron line, with || for failures or && for success.
3. **Get alerted** — Run the job. If it fails, your phone buzzes with the title and error output you set.

## Never miss a failed job again

A failed import should reach you right away, hours before you open the logs.

- **One line in crontab** — Chain a push onto any cron line with && or ||. It is one curl call, with no daemon to babysit.
- **Alert only on failure** — With ||, the alert fires only when the command exits non-zero.
- **Include the error** — Pipe stderr or the exit code into the message, so the push arrives with the error already attached.
- **Any scheduler** — crontab, systemd timers, the Laravel scheduler, Sidekiq, and K8s CronJobs all work, because every one of them runs commands.
- **Heartbeat on success** — Send a heartbeat after a successful run. When it stops arriving, you know the job died quietly and can dig in.
- **Instant on finish** — The push lands as the job exits, hours before anyone tails the logs.

## Wire an alert into your cron job

### Install and authenticate the CLI

```
sudo mv pocketalert /usr/local/bin/ && chmod +x /usr/local/bin/pocketalert
pocketalert auth YOUR_API_KEY
```

### Alert only when the job fails

Chain the alert with `||` so it fires only on a non-zero exit code:

```
0 3 * * * /usr/local/bin/mybackup.sh || pocketalert send \
  -t "Cron failed: mybackup" -m "Exited non-zero at $(date)"
```

### Include the error output

```
0 3 * * * /usr/local/bin/mybackup.sh 2>/tmp/cron.err || pocketalert send \
  -t "Cron failed: mybackup" -m "$(tail -n 3 /tmp/cron.err)"
```

### Heartbeat on success

Add a ping with `&&` after a clean run. When it stops arriving, the job died quietly:

```
0 3 * * * /usr/local/bin/mybackup.sh && pocketalert send "Cron OK: mybackup" "Finished cleanly"
```

### No CLI? Call the API with curl

```
0 3 * * * /usr/local/bin/mybackup.sh || curl -X POST "https://api.pocketalert.app/v1/messages" \
  -H "Token: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title":"Cron failed: mybackup","message":"Exited non-zero","level":"high"}'
```

The [docs](https://info.pocketalert.app/getting-started.html) cover targeting and per-application channels.

## FAQ

### How do I get alerts from cron jobs?

Chain a notification onto your cron command in the shell. `&&` fires after a successful run, `||` fires after a failure, and Pocket Alert sends the push notification when the job exits.

### Can I alert only on failure?

Use `||` so the alert fires only when the command exits non-zero: `mybackup.sh || curl ...`. Broken jobs reach you while the rest stay quiet.

### Can I include the error output?

Yes. Capture the exit code or output and drop it into the message body. The Pocket Alert CLI pipes stderr straight into the notification.

### Does this work beyond crontab?

Any scheduler works: crontab, systemd timers, the Laravel scheduler, Rails or Sidekiq cron, Windows Task Scheduler, Kubernetes CronJobs. If it runs a command, you can chain an alert onto it.

### Can I detect a job that never ran?

Send a completion ping with `&&` after every successful run. Once the ping stops arriving, you know the job stopped running, and no extra tooling is involved.

### Can a failed nightly job wake me up — and success pings stay silent?

Add level=critical to the failure alert and it breaks through Do Not Disturb on Android and cuts through Focus on iPhone. For heartbeat pings, use level=silent — they land in your history without a sound, so the record is there but your phone stays quiet.
