From c6fd6907129d69b3f0d96cd1b57147dcfe65a74b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 1 Jun 2018 18:40:43 +0100 Subject: [PATCH] ping-service.sh --- ping-service.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 ping-service.sh diff --git a/ping-service.sh b/ping-service.sh new file mode 100755 index 0000000..e79842e --- /dev/null +++ b/ping-service.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# I am a script, intended to run from `cron`, which pings a +# configurable URL, and if no suitable response is forthcoming, +# performs a configurable command. +# +# For example, to monitor racket-pkg-website, try +# +# ./ping-service.sh https://localhost:8444/ping 'touch .../signals/.dumpinfo; svc -du ...' + +if [ "$#" != "2" ] +then + echo 'Usage: ping-service.sh ' + echo 'Note that has to be a single string.' + exit 1 +fi + +url="$1" +failurecommand="$2" + +# curl flags: +# -f == fail, interrogate the HTTP response status code +# -s == silent, don't print a progress meter or any other cruft +# -k == Ignore certificates, where url is an HTTPS URL +# +if curl -f -s -k --max-time 10 "$url" > /dev/null +then + # Do nothing -- the retrieval was successful + true +else + exec sh -c "$failurecommand" +fi