# Monitor a cron job or script

> Most checks reach out to something of yours. A heartbeat monitor works the other way around: your backup script, cron job or scheduled task calls in to…

Source: https://infranest.io/docs/monitor-a-cron-job
Last updated: 2026-09-19

---

Keep an eye on a backup script, cron job or scheduled task by having it check in with InfraNest — this is for anyone who wants to know the moment a routine job silently stops running.

## Overview
- A heartbeat monitor works in reverse to most checks: instead of InfraNest reaching out to your service, your job calls in to InfraNest each time it finishes.
- If the call-in doesn't arrive on time, InfraNest raises an alert.
- This is the best way to catch a job that has quietly stopped running, rather than one that's just slow to respond.

## Set one up
1. Go to **Monitors** and select **add a monitor**.
2. Choose **Heartbeat / Cron monitor** as the type.
<!-- screenshot: monitor-a-cron-job -->

<!-- docs-screenshots:start:monitor-a-cron-job -->

![Monitor a cron job or script](/media/53ffe908-767d-4e81-9e49-8d99b241fbd4)

<!-- docs-screenshots:end:monitor-a-cron-job -->

3. Give it a **name** you'll recognise in an alert — "Nightly database backup" beats "job 1".
4. Set the **check interval** to how often the job is supposed to run.
5. Set a **grace period** — extra time allowed before the job is called late. A backup that usually takes four minutes but occasionally takes eight needs a grace period comfortably longer than that overrun.
6. Select **create monitor**.

You don't enter a URL for this type — InfraNest creates one for you when you save.

## Make your job check in
1. Open the monitor to see its **ping URL**, plus a ready-to-paste one-liner.
2. Add that line to the **end** of your script or cron job, so it only runs when the job actually succeeded:

```
0 3 * * *  /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 https://your-infranest-url/api/heartbeat/your-uuid
```

3. Keep the `&&` in place — it means the check-in only happens if the backup itself exited successfully. A failed job then stays silent, and silence is what raises the alert.
4. Use the **Copy** button rather than retyping the URL — the identifier in it is unique to this monitor.

## What happens next
- Every check-in marks the monitor **Active** and records the time as its last ping.
- A brand-new monitor stays pending until its first window has passed, so you have time to wire the check-in up without being alerted about it.
- If nothing arrives within the interval plus the grace period, the monitor goes **Inactive** and opens an incident, so your usual alert destinations fire.
- The next check-in resolves the incident and alerts you that it's back — you don't have to close it by hand.

> [!NOTE]
> Pausing a heartbeat monitor is safe: the ping URL keeps answering normally, so a job that's still calling it won't start reporting failures. InfraNest simply stops watching until you resume.

> [!TIP]
> Treat the ping URL as a secret. Anyone who has it can report your job as healthy — which would hide a real failure.

## Troubleshooting
- **No ping received yet** on the monitor means InfraNest hasn't heard from the job at all. Run the curl line by hand from the same machine: if that turns the monitor Active, the problem is in your script, not here.
- If the machine can't reach the internet outbound, the check-in can't arrive — allow outbound HTTPS to InfraNest.
- A monitor that alerts every night at the same time usually has a grace period shorter than the job's real worst-case runtime.
