Posted in Linux Scripts

Script : check services status easily

December 14, 2005 - 1 comment

Since arpwatch and spamassassin crashed for some unknown reasons (probably bugs) lately, I needed a tool that would monitor services status on a regular basis.

I found Nagios http://www.nagios.org/ but it was not really what I needed. Indeed, Nagios can only monitor some specific services (usually services opening a tcp port) and it offered just way too many features, thus requiring a lot of dependencies and was not the easiest piece of software to install.

To do the job, I made this (very) little script that runs from a cron on a daily basis :

#!/bin/sh

SERVICES_REGULAR="squid smb 3dm mysqld postfix frox dhcpd sshd spamassassin httpd courier-imap arpwatch xinetd"

echo "Services"
echo "========"
for services_regular in $SERVICES_REGULAR
do
/sbin/service $services_regular status | sed -re 's/(pid|\(|\)|[0-9]{2,}|\.\.\.|\ )//g;s/\is/ : /g'
done
/sbin/service named status | grep server | sed -re 's/server/named/g;s/is/:/g'
echo " "

The output is :

Services
========
squid : running
smbd : running
nmbd : running
3dmd : running
mysqld : running
master : running
Frox : running
dhcpd : running
sshd : running
spamd : running
httpd : running
arpwatch : running
xinetd : running
named : up and running

This should work on many Redhat flavors, if you take a look at the code, named doesn’t output a regular “service is (running|stopped)”, I needed to make a special line for this service

Comments

The Adminblogger

February 1, 2007 - 10:10

Do you know monit? This tiny tool can monitor processes, e.g. look at pid files in /var/run and check if the corresponding process is running. if not, it can try to restart the application. monit itself is started via inittab to make sure it get’s restarted automatically if someone kills monit or it crashes.

Leave Comment

Please consider visiting the partners below if you enjoyed this article :

If this post saved you time and money, please consider checking my Amazon wishlist.

Before submitting, some rules :
- Is your comment related to the article ?
- You're having a problem ? Have you checked Google, other howtos, docs, manpages ?
- You're still having the problem ? Have you raised log verbosity, checked traces, ran tcpdump ?
- Have you checked your configuratoin for typo ?
Unless your comment is providing additional info or respect the rules above, DON'T comment.
If you don't understand what you are doing, I urge you to read the documentation, I'm not your free Level 1 helpdesk guy.