Skip to content

Instantly share code, notes, and snippets.

@LiamKarlMitchell
Created March 17, 2021 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LiamKarlMitchell/38822176b5fa0c4b2ecc89413fa635bb to your computer and use it in GitHub Desktop.
Save LiamKarlMitchell/38822176b5fa0c4b2ecc89413fa635bb to your computer and use it in GitHub Desktop.
HealthChecks SH wrapper for Cron Job Notifications/Monitoring.
#!/bin/sh
# Author: Liam Mitchell
# Purpose: Wrap a cron command and ping HealthChecks.io
HEALTHCHECKS_UUID=$1
# Check number of arguments is at least 1 for the Health Checks UUID.
if [ -z "$1" ];
then
echo "Usage: `basename $0` HEALTHCHECKS_UUID command args..."
exit 65
fi
# Set lockfile name and location
lockfile="/tmp/${HEALTHCHECKS_UUID}.lock"
# echo Lockfile: ${lockfile}
# Check if the lockfile exists.
if [ -f $lockfile ]; then
# If the lockfile exists quit.
echo Lockfile: ${lockfile} already exists.
exit;
# If the lockfile is missing continue.
else
# Create the lockfile.
touch $lockfile
# Start
curl -s -m 10 --retry 5 https://hc-ping.com/${HEALTHCHECKS_UUID}/start > /dev/null
# Payload here, remove the first argument and run the rest of arguments.
shift 1
"$@"
# Ping HealthChecks.io.
curl -s -m 10 --retry 5 https://hc-ping.com/${HEALTHCHECKS_UUID}/$? > /dev/null
# Cleanup the lockfile
rm -f $lockfile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment