Nagios plugin check_mailfromd bash script

In this post we will create Nagios plugin check_mailfromd in bash script.This nagios plugin is written in a very simple way and easy to understand.

Task

To check service status of mailfromd service.

Create nagios plugin check_mailfromd

Create a new bash script file called check_mailfromd. Use your favorite file editor for this, we in general use vi/vim.

vi check_mailfromd

Now paste the given below contents in check_mailfromd file.

#!/bin/bash

#Author Sharad Kumar Chhetri
#script is used for checking mailfromd status

mailfromdp=`/usr/bin/sudo /etc/rc.d/init.d/mailfromd status | grep running | awk '{ print $5 }'`
if [ "$mailfromdp" == "running" ]
then
echo "OK: mailfromd is running"
exit 0
else
if [ "$mailfromdp" != "running" ]
then
echo "CRIT: mailfromd is not running"
exit 2
fi
fi

Copy the script with name check_mailfromd in /usr/lib64/nagios/plugins/ location.(This location appear when you use rpm rather than tarball for nagios configuration)

cp check_mailfromd /usr/lib64/nagios/plugins/

Give executable permission to script.

chmod +x /usr/lib64/nagios/plugins/check_mailfromd

Change the ownership and group of file.

chown nagios:nagios /usr/lib64/nagios/plugins/check_mailfromd

Now nagios plugin check_mailfromd is ready to use.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.