scripts/Linux/zabbix/check_service.sh

28 lines
582 B
Bash
Raw Normal View History

2023-08-22 09:16:23 +02:00
#!/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