background-hooknotifierbackground-hooknotifier
Last update: Jul 05, 20261 minutes read

Get notified when a cron job finishes or fails

low-code

Get a push notification when a cron job finishes, or only when it fails. Add one line to the end of your script and call your Hook.Notifier URL. No agent. Free.

To get notified when a cron job finishes, add a call to your Hook.Notifier URL at the end of the script it runs. When the job is done, your phone gets a push notification. You can ping yourself on success, only on failure, or both.

Notify when the job finishes

Add one line at the end of the script your cron runs:

# your nightly job
./backup-database.sh

# ping when it is done
curl -s "https://hooknotifier.com/{IDENTIFIER}/{KEY}?object=Backup%20done&body=Nightly%20database%20backup%20finished"

That is it. Every run drops a notification on your phone, so a job that quietly stopped running is impossible to miss.

Notify only when it fails

Most of the time you do not want a ping for every successful run. You want to hear about it only when something breaks. Check the exit code and notify on failure:

#!/bin/bash
if ./backup-database.sh; then
  : # success, stay quiet
else
  curl -s "https://hooknotifier.com/{IDENTIFIER}/{KEY}?object=Backup%20FAILED&body=Nightly%20backup%20exited%20with%20an%20error&priority=high&color=%23EE6767"
fi

The priority=high matters. A broken backup should not wait until you happen to check a dashboard: high and critical priority cut through your quiet hours, so a 3am failure still buzzes. The red color makes it stand out in your inbox at a glance.

hook notifier notification

First get your URL

Your Hook.Notifier URL is https://hooknotifier.com/{IDENTIFIER}/{KEY}. Create a free account to get yours, then drop it into your script.

Report how long it took

Since it is just a shell script, you can put anything in the body. Time the run and send it along:

#!/bin/bash
start=$(date +%s)
./backup-database.sh
elapsed=$(( $(date +%s) - start ))
curl -s "https://hooknotifier.com/{IDENTIFIER}/{KEY}?object=Backup%20done&body=Finished%20in%20${elapsed}s"

Now the notification tells you not just that the job ran, but whether it is creeping slower over time.

Why it matters

A cron job is the classic silent point of failure. It works for months, then one night it stops, and nobody notices until a customer does. A single line that pings your phone turns an invisible job into one you can actually trust.

New to this? Start with how to send yourself a native push notification, or see the same idea for any shell script.