Posted in Linux Scripts
Script : check services status easily
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
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.







The Adminblogger
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.