Task notifications cron · CLI

Catch backup and scheduled-job failures

Send the failure of an unattended job to your phone, with enough context to investigate.

Prepare server notifications

Updated

An overnight job needs your attention.

nightly-backupExample message

Backup failed

The backup returned an error. Check available storage and the job log.

When to use it

A backup runs while you sleep. If the command starts and returns an error, the script can notify you and retain the failure status for its scheduler. Keep the message short, name the job, and point yourself to its existing log.

Connect in three steps

  1. Use the scheduler’s account

    Install and pair the CLI as the user that runs the scheduled job. Check the absolute CLI path.

  2. Notify on the failure path

    Save the job exit status, send a failure summary and return the original status to the scheduler.

  3. Test in the scheduled environment

    Run a harmless failure with the scheduler’s PATH and configuration. Then attach the pattern to the existing backup script.

Start here

First, get Ntfyx on your phone

On a computer? Click a store to scan its QR code with your phone.

iPhone · 1.6.4

Get Ntfyx on your phone

Scan with your phone camera to open App Store.

QR code linking to Ntfyx on App StoreOpen App Store

This is a store link. It does not connect or authorize a device.

Android · 1.6.4

Get Ntfyx on your phone

Scan with your phone camera to open Google Play.

QR code linking to Ntfyx on Google PlayOpen Google Play

This is a store link. It does not connect or authorize a device.

Check that it works

This POSIX shell rehearsal uses false, so it does not touch backup files. Run it with sh and confirm the phone gets a failure message and the script exits 1. Replace false with true to check that a successful run remains quiet. In cron, use verified absolute paths or set PATH explicitly.

Example to copy
# Harmless failure rehearsal; no backup files are touched.
task_status=0
false || task_status=$?
if [ "$task_status" -ne 0 ]; then
  ntfyx send "Backup test failed (exit $task_status)" || \
    printf '%s\n' 'Notification failed; inspect the job log.' >&2
fi
exit "$task_status"

What to know

This detects errors returned by a job that actually ran. A powered-off host or a job that never starts cannot execute its notification; detecting missed runs needs a separate heartbeat mechanism. Notification delivery also depends on connectivity and limits. Keep your scheduler’s logs so a notification failure remains visible.