Skip to content

Instantly share code, notes, and snippets.

Last active May 14, 2021 14:43
What would you like to do?
Run a command and report status to
#!/bin/bash -eu
set -o pipefail
# Run a command and report status to
usage() {
echo "Usage: $0 < UUID> <command>"
exit 1
trap usage EXIT
URL="${1:?No UUID provided}"
trap - EXIT
healthcheck() {
# Log output is limited to 10,000 bytes, so let's send the tail
# as that's likely more useful for debugging
OUTPUT=$(echo "${OUTPUT}" | tail --bytes=10000 -)
curl \
--fail --silent --show-error \
--retry 5 -o /dev/null \
--data-raw "${OUTPUT}" \
report_start() {
healthcheck "${URL}/start"
report_rc() {
healthcheck "${URL}/${RC}"
exit ${RC}
trap report_rc EXIT
healthcheck "$URL/start"
# Run command and store output in $OUTPUT for logging at
OUTPUT=$($@ 2>&1)
Copy link

rcj4747 commented May 14, 2021

I use this in my crontab to wrap jobs. The tools like this in the docs @ all were trying to do too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment