add check_service_bsd.sh

This commit is contained in:
Cyberes 2023-06-08 11:34:49 -06:00
parent 0c8f675676
commit 5f5f831d02
Signed by: cyberes
GPG Key ID: 6B4A33836A9500FE
1 changed files with 38 additions and 0 deletions

38
check_service_bsd.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/sh
# Parse named arguments
while [ "$#" -gt 0 ]; do
case "$1" in
--service=*)
SERVICE="${1#*=}"
shift 1
;;
*)
echo "Unknown option: $1"
exit 3
;;
esac
done
# Check if the service name is provided
if [ -z "$SERVICE" ]; then
echo "UNKNOWN - Service name not provided"
exit 3
fi
# Check if the service is running
service_status=$(service ${SERVICE} onestatus)
# If the service is running, return OK
if echo "$service_status" | grep -q "${SERVICE} is running as pid [0-9]*."; then
echo "OK - ${SERVICE} is running"
exit 0
# If the service is not running, return CRITICAL
elif echo "$service_status" | grep -q "${SERVICE} is not running."; then
echo "CRITICAL - ${SERVICE} is not running"
exit 2
# If the check failed, return UNKNOWN
else
echo -e "UNKNOWN - Check failed:\n$service_status"
exit 3
fi