diff --git a/check_service_bsd.sh b/check_service_bsd.sh new file mode 100755 index 0000000..7a76bae --- /dev/null +++ b/check_service_bsd.sh @@ -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