Network and Systems Management

Unix/Linux Check Service Status

Description:

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.

Current Version

Last Release Date

2014-01-23

Compatible With

  • Nagios 3.x
  • Nagios 4.x
  • Nagios XI

Owner


Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Project Notes
Check status of system services for Linux, FreeBSD, OSX, and AIX. Options: -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) Add a Review
In case of "unable to read output"
by KpuCko, September 30, 2021
Please check and disable your sestatus (selinux)
Helpful? Yes  No 
Very useful
by akashimd, December 31, 2019
I have used this script in environmentand successfully able to monitor thr service

Thanks For this 68
Helpful? Yes  No 
Nice with minor issue
by stefanslawidis, August 31, 2018
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"
LISTTOOL="systemctl"
if [ $USERNAME ]; then
SERVICETOOL="sudo -u $USERNAME systemctl status $SERVICE"
LISTTOOL="sudo -u $USERNAME systemctl"
fi
TRUST_EXIT_CODE=0 # changed from 1 to 0

Maybe this will help some one or you can fix it permenantly.
Kind regards
1 of 1 found this review helpful.
Helpful? Yes 1 No 0
Problem running script.
by xilefm, January 31, 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 ?
Helpful? Yes  No 
Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.6 (7)
Favorites
4
Views
92,507