Created
March 17, 2021 23:45
-
-
Save LiamKarlMitchell/38822176b5fa0c4b2ecc89413fa635bb to your computer and use it in GitHub Desktop.
HealthChecks SH wrapper for Cron Job Notifications/Monitoring.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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