scripts/Linux/zabbix/check_service.sh

28 lines
582 B
Bash
Executable File

#!/bin/bash
# find service name from argument
monitorService=$1
# check if $monitorService is empty
if [ -z "$monitorService" ]; then
read -p "Please pass me the service name: " monitorService
fi
# define the check_service function
function check_service {
# check if the service is active and report so
if systemctl is-active --quiet $monitorService; then
echo "$monitorService is running"
# if the service is not running, exit with an error.
else
echo "$monitorService is not running"
exit 1
fi
}
# excecute the check_service function
check_service