Skip to content

Search setups and tools

Type a few words to search.

Browse all setups

Alert when a 2 a.m. job fails

Get an email or text when a nightly job fails or never runs, by having Claude Code wrap the script and report to a heartbeat check.

For owners and one-person IT who run a nightly script on a Mac, Linux machine or server, such as a backup or export · Claude Code · Intermediate

Researched, not run yetWhat that means

Copy the prompt

Fill in the [brackets] after you paste it.

I have a nightly job that runs from cron on this machine. Write a small shell script that wraps it and reports to Healthchecks.io.

The job command: /home/shop/bin/export-orders.sh (made-up sample).
Its schedule: 3:30 AM every day (a sample time chosen outside the hour when clocks change; check yours).
It normally takes a few minutes.

The wrapper must:
1. Send a "start" ping, run the job command, and save its output to a log file in a logs folder next to the script.
2. If the job exits with 0, send a success ping. If it exits with any other code, send a failure ping with the exit code, and keep the log.
3. Read the ping URL from an environment variable named HC_PING_URL, or from a private file, never from the script text. Never print the URL.
4. Use curl with a short timeout and a few retries, so a network problem does not hang the job. If the ping fails, write that to the log. Never delete or change the job's own output.
5. Exit with the job's own exit code.

Also:
- Show me the single crontab line to run the wrapper at the same time, loading the ping URL from the private file or environment, never written in the line. Do not edit my crontab yourself.
- Tell me how to test a failure on purpose and how to test a missed run.
- Do not change the job script, do not install anything and do not send anything except the pings. Before you run anything, say what you will do.

Three ways to run this setup

  • Free

    Copy and paste it yourself

    Copy the prompt above into ChatGPT, Claude or Grok. It drafts. You approve.

    Go to the prompt
  • $9 once

    Complete Pack

    One payment, no membership. Opens the pack pages: Bot Safety Checklist, Second Brain Starter Vault, Voice File Starter, Tested Grok Bot prompt pack, Write it as code prompts.

    See the Complete Pack
  • Free to start, VIP $19 a month

    Save it as a bot in the guided setup app

    The app turns this setup into a bot with the draft-only rules. 3 setups build free; the rest are part of VIP. A human reviews a prompt or setup for you within 24 hours, up to 2 a month.

    Build it in the app

Want this one tested next? Vote for it.

What you get back

Example written for this page with made-up details. Not from a test run.

  • Created run-with-alert.sh. It pings start, runs export-orders.sh, writes logs/export-orders-2026-11-16.log, then pings success or failure and exits with the job's exit code. The ping URL is read from a private file.
  • Cron line to add yourself: 30 3 * * * /home/shop/bin/run-with-alert.sh (3:30 AM is a sample time outside the clock-change hour). The wrapper loads the ping URL from a private file at /home/shop/.hc-ping-url, so the URL never appears in the cron line.
  • To test a failure: run the wrapper with the job replaced by false and look for the alert email. To test a missed run: skip one night and wait past the grace time.

3 steps

  1. Copy the prompt.
  2. Paste it into Claude Code.
  3. Fill in the [brackets], then read the answer before you send or use it.

Quick answer

Have Claude Code write a small wrapper around the nightly job. The wrapper runs the job, then pings a monitoring check: one ping for success, another for failure. If the job fails, the wrapper sends a failure ping and the check alerts right away. If the job never runs at all, no success ping arrives, and the check goes overdue and alerts once the grace time passes. You add the schedule line yourself. Test it by making the job fail on purpose and by skipping a run.

How do you set it up?

Skip this if

  • The job runs on a hosting dashboard or Windows Task Scheduler. The steps here are for cron on macOS or Linux.
  • You cannot install a script or edit a crontab on the machine.

Done after day one

A wrapper script, a cron line you added yourself, and one test alert that arrived.

Tools

  • A Mac or Linux machine that runs the job from cron, and is on at night
  • The command that runs the job, written out in full
  • A Healthchecks.io account, or another heartbeat service with the same ping idea
  • Claude Code, in the terminal or the desktop app

Steps

  1. Write down the job: the exact command, the time it runs, how long it normally takes and where its output goes now.
  2. In Healthchecks.io, create one check for this job. Set the schedule to match cron (a Cron schedule, with the expression from your crontab and your machine's time zone) and set the Grace Time longer than the job normally takes. Copy the check's ping URL.
  3. Add at least one notification method, and a second one if the job matters, such as email and a chat or text. Two channels give a second chance if one fails, but neither is a guarantee of delivery.
  4. Open Claude Code in a new folder in Manual mode and paste the prompt below with your command. Do not paste the ping URL into the chat or into any file that is shared; the prompt has you put it in an environment variable or a private file.
  5. Read what Claude Code wants to do and approve each action. It should write the wrapper and show you the cron line. It should not edit your crontab.
  6. Add the cron line yourself with crontab -e. Pick a time outside the hour when the clocks change.
  7. Test the failure alert. Run the wrapper by hand with a command that fails, such as false, and wait for the email.
  8. Test the missing-run alert. Leave the job off for one scheduled run and confirm the check goes late and alerts after the grace time.
  9. Put the check's name, the ping URL location and what to do when it alerts into one note, so whoever gets the alert knows the next step.

Where to paste this prompt

Claude Code → terminal, IDE extension, or web session in your project directory

More ways to run it

Which chat tools work with this prompt?

Paste the prompt into any of these assistants (free or paid tiers).

  • Claude Code

How sure is this?

ResearchedDrafts for you

Operations · Intermediate · Small business

Last updated: · Last reviewed:

Before you use this

Who it is for: Owners and one-person IT who run a nightly script on a Mac, Linux machine or server, such as a backup or export, and only learn it failed days later.

What it is allowed to do: Drafts for you. Writes drafts (emails, posts, plans, replies). You review and send. Nothing goes out without you.

At a glance: time, cost and difficulty

At a glance

All outcome figures are estimates from cited sources, not independent verification by us.

What it is allowed to do
Drafts for you

Writes drafts (emails, posts, plans, replies). You review and send. Nothing goes out without you.

Reviewed Nov 16, 2026

Time saved (estimate)
Not measured yet
Difficulty
Intermediate
Tools needed
Claude Code, Healthchecks.io, cron
Typical cost
Claude Code needs a paid Claude plan or a Claude Console account (claude.com/pricing). Healthchecks.io has its own plans and a self-hosted option: see healthchecks.io/pricing. cron is built into macOS and Linux.

Basis (estimate): Not measured yet. No timing has been recorded for this setup.

What usually goes wrong?

Where agents tend to stall on this job. More patterns in Where AI gets stuck.

  • The cron job has a different PATH or environment from your shell. Use full paths in the wrapper and the cron line.
  • The success ping fires even though the job half-failed. The job itself has to exit with a non-zero code when it fails, so test that.
  • No alert arrives. Check the notification method on the check, your spam folder and that the check is not Paused.
  • The check is always late by an hour. The time zone on the check does not match the machine.
  • The machine is off or asleep at night. The check will alert, which is the point. Run the job on a machine that stays on.

What tips make it smoother?

  • Set the grace time longer than the job normally takes, or you get an alert for a slow night.
  • Send the alert to two places. The docs recommend more than one channel in case one fails.
  • Look at the check page once a week. The service can also send weekly or monthly email reports.

Where do the claims come from?

Summaries use public sources linked below, not independent verification. How setups are picked.

Common questions

Does Claude Code watch my job?
No. It writes the wrapper script. The script and the monitoring check do the watching when Claude Code is closed.
What if the job never starts?
That is what the heartbeat is for. The check expects a ping on schedule and alerts when none arrives within the grace time. Test it by skipping a run.
Why not use the email that cron already sends?
The Healthchecks.io docs list the drawbacks: it needs a configured mail system, it says nothing if the machine is off, and a noisy job can bury real errors.

Free kit by email

Get the free kit by email

The starter pack and the Portable AI Office, sent to your inbox. New setups by email after that. Unsubscribe any time.

What to do next