Skip to main content

Dead Man's Snitch - CronJob Monitoring: Get Email Alerts for CronJob Failures

317 words·
Dead Man's Snitch CronJob Monitoring

A Dead Man’s Snitch is a monitoring tool that alerts you if a scheduled job like a CronJob fails to run on time.

This is useful as a simple backup monitoring system, sending notifications if the main monitoring system crashes.


Dead Man’s Snitch
#

Create an Account & Snitch
#

  • Create an account at https://deadmanssnitch.com/ and confirm the account email

  • Select a plan, like TINY: The Lone Snitch for free usage

  • Create a new snitch

  • Define a name for the snitch like “My-snitch”

  • Define an interval like 1 hour (the smallest available with free usage)

  • Optional, define an alert email address, the default is your account email

  • Click “Save”

  • Copy the snitch URL, like this one: https://nosnch.in/88eed15a2e


Create a Snitch Script
#

Create a script that makes a curl request to the snitch URL to report that the job has run:

# Create a directory for the snitch script
sudo mkdir -p /opt/snitch

# Create the snitch script
sudo vi /opt/snitch/report_snitch.sh
#!/bin/bash

# Define Snitch URL
SNITCH_URL="https://nosnch.in/88eed15a2e"

# Report to the Dead Man's Snitch
curl -s $SNITCH_URL > /dev/null
  • curl -s Silent mode suppresses the progress meter and error messages, allowing the command to run quietly without displaying any output to the terminal. Itt does not stop curl from outputting the response content.

  • /dev/null Discard the output of the command.

# Change the permissions of the script
sudo chmod +x /opt/snitch/report_snitch.sh

Create CronJob
#

# Create a system wide CronJob
sudo vi /etc/crontab

# Define CronJob
*/2 * * * *     root    /opt/snitch/report_snitch.sh

Verify the CronJob was created:

# Grep the syslog
grep cron /var/log/syslog

# Shell output:
Oct 18 20:06:01 host1 cron[865]: (*system*) RELOAD (/etc/crontab)

Verify the Snitch
#

  • Open the previously created snitch and verify it was curled through the CronJob:

Note: You should also receive an email when the Snitch is curled for the first time.


Links #

# Dead Man's Snitch Website
https://deadmanssnitch.com/