Home Directory Plugins Network and Systems Management Unix/Linux Check Service Status

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com


Remember Me

Directory Tree

Unix/Linux Check Service Status

7 votes
Last Release Date
Compatible With
  • Nagios 3.x
  • Nagios 4.x
  • Nagios XI
Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
Linux/Unix shell script to check the status of a service. Capable of using
sysvinit, systemd, upstart, etc, or choose your own status command.

Tested on Ubuntu Linux, Fedora Linux, Red Hat Linux, FreeBSD, OSX, and AIX.
Check status of system services for Linux, FreeBSD, OSX, and AIX.

-s Specify service name
-l List services
-o OS type, "linux/osx/freebsd/aix"
-u User if you need to ``sudo -u'' for launchctl (def: nagios, osx only)
-t Manually specify service management tool (def: autodetect) with status and service e.g. ``-t "service nagios status"''

# Author: Jon Schipp

# Examples:

# 1.) List services for osx
# $ ./check_service.sh -l -o osx
# 2.) Check status of SSH service on a linux machine
# $ ./check_service.sh -o linux -s sshd

# 3.) Manually select service management tool and service
# $ ./check_service.sh -o linux -t "service rsyslog status"
Reviews (4)
Please check and disable your sestatus (selinux)
byakashimd, December 28, 2019
I have used this script in environmentand successfully able to monitor thr service

Thanks For this 68
bystefanslawidis, August 30, 2018
1 of 1 people found this review helpful
First of all great script. I'm running RedHat 7.5 and had a problem with the $TRUST_EXIT_CODE. The check was allways ok, even when the checked service was not running. Because of line 255:

[ $TRUST_EXIT_CODE -eq 1 ] && [ $EXIT_CODE -eq 0 ] && echo "Trust $STATUS_MSG" && exit $OK

I changed in the if section for $OS == linux line 85 from $TRUST_EXIT_CODE=1 to $TRUST_EXIT_CODE=0 and script is working as expected.

determine_service_tool() {
if [[ $OS == linux ]]; then
if command -v systemctl >/dev/null 2>&1; then
SERVICETOOL="systemctl status $SERVICE | grep -i Active"
if [ $USERNAME ]; then
SERVICETOOL="sudo -u $USERNAME systemctl status $SERVICE"
LISTTOOL="sudo -u $USERNAME systemctl"
TRUST_EXIT_CODE=0 # changed from 1 to 0

Maybe this will help some one or you can fix it permenantly.
Kind regards
byxilefm, January 19, 2017
I canĀ“t get this script to work when running check_nrpe from nagios server.

Only get NRPE: Unable to read output

Running script directly on server to check works fine.

Am i missing something here ?