Skip to content

Instantly share code, notes, and snippets.

@mpql
Created March 24, 2022 21:06
Show Gist options
  • Save mpql/3661ff5f293c2bc6f3eec6fdc96cf13d to your computer and use it in GitHub Desktop.
Save mpql/3661ff5f293c2bc6f3eec6fdc96cf13d to your computer and use it in GitHub Desktop.
Script to check service status and hit URL ; intended to be cron'd
#!/bin/bash
service=${1} ;
url=${2} ;
if [[ -z "${url}" ]] || [[ -z "${service}" ]]
then
echo 'Argument missing.' ;
echo 'Usage: check-service.sh [servicename] [push URL]' ;
exit
fi
/bin/systemctl -q is-active "${service}.service" ;
status=$? ;
if [[ "${status}" == 0 ]] ; then
curl --silent --max-time 6 --output /dev/null "${url}" ;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment