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
2023-08-22 15:56:34 +02:00
# find service name from argument
2023-08-22 09:16:23 +02:00
monitorService=$1
2023-08-22 15:56:34 +02:00
# check if $monitorService is empty
2023-08-22 09:16:23 +02:00
if [ -z "$monitorService" ]; then
read -p "Please pass me the service name: " monitorService
fi
2023-08-22 15:56:34 +02:00
# define the check_service function
2023-08-22 09:16:23 +02:00
function check_service {
2023-08-22 15:56:34 +02:00
# check if the service is active and report so
2023-08-22 09:16:23 +02:00
if systemctl is-active --quiet $monitorService; then
echo "$monitorService is running"
2023-08-22 15:56:34 +02:00
# if the service is not running, exit with an error.
2023-08-22 09:16:23 +02:00
else
echo "$monitorService is not running"
exit 1
fi
}
2023-08-22 15:56:34 +02:00
# excecute the check_service function
2023-08-22 09:16:23 +02:00
check_service