A Nagios-plugin to check if a device is mounted.

Those of you that have a bigger NFS infrastructure may know the problem, that some shares may unmount itself or won’t be mount correctly after reboot. This plugin checks whether a device a mounted on a specific mount point.

To run it just give it the mount point you’re looking for:

USAGE: ./check_mount.pl
        -m MOUNTPOINT   wich mountpoint to check
        [-t TYPE]       optionally check whether it's this kind of fs-type

If you additionally define which mount type you expect, this plugin will check whether your expectation matches. Just try it out ;)
Maybe you have to modify the location of your utils.pm by updating the lib -path in line 13.

Here is the code.


Please consider to take a look at my general setup notes.

Download: Perl: check_mount.pl (Please take a look at the man-page. Browse bugs and feature requests.)

Martin Scharm

stuff. just for the records.

Do you like this page?
You can actively support me!


Liju | Permalink |


I’m strugging to set this plugin up. I can execute it correctly from the CLI but nrpe is showing NRPE: Unable to read output

[root@fc-web04 libexec]# /usr/bin/perl /usr/local/nagios/libexec/check_mount.pl -m /var/Performance
/var/Performance is mounted!

This is the error I’m getting

[root@fc-web04 libexec]# ./check_nrpe -H localhost -c check_df
NRPE: Unable to read output

Can you pls guide me how could I make it work ?

Thanks in advance Liju

Liju | Permalink |

Make it worked by adding nagios plug-ins directory in that script file like this use lib '/usr/local/nagios/libexec';

Martin Scharm | Permalink |

Hi Liju,

I expected to find the Nagios’ utils.pm in /usr/lib/nagios/plugins . I’ll update my articles to supplement it with a note about this variable ;-)

Thanks for your advice!

Anders Holm | Permalink |

First off, sane exiting from the usage statement, in the event someone adds a check, but forgets the mount point..

sub how_to
	print "USAGE: $0\n\t-m MOUNTPOINT\twich mountpoint to check\n\t[-t TYPE]\toptionally check whether it's this kind of fs-type\n\n";
	print "OK: We really have no idea what you want to check, so we'll play it safe here, alright?\n";
	exit $ERRORS{'OK'};

In case of a mount point sitting under another like this:

/opt/something mounted from /dev/sdb
/opt/something/shared mounted from NFS

then you actually catch both in your $erg grep … To only catch the one filesystem you are looking for is doing something like this (ugly) hack ..

my $erg = `mount | grep $MOUNT | awk '{ print \$3\" \"\$5 }' | grep -v ^$MOUNT\/`;
chomp $erg; #I tend to get rid of newlines ...

Also CIFS mounts may lose connectivity to the server sharing the folder, but will recover on its own. In the meantime you’ll not be able (of course) to do anything with data in that mountpoint. What distinguishes things is simply a directory listing which will contain nothing but a number of question marks if you do a long listing ( ls -l ) ..

user@host $ ll /opt/some_dir
total 0
?--------- ? ? ? ?            ? another_dir

So, I’ve added a little bit of code, for this specific case (and changed a regexp along the way) …

if ($erg)
	if (defined ($TYPE))
		if ($erg =~ m/$TYPE/x)
		{ if ($TYPE eq "cifs") {
			my $fs_listing = `ls -larth $MOUNT`;
			if ($fs_listing =~ m/\?/x) {
				print "WARNING: " . $MOUNT . " is mounted but we cannot access files!!\n";
				exit $ERRORS{'WARNING'};

			print "OK: " . $MOUNT . " is mounted! Type is " . $TYPE . "\n";
			exit $ERRORS{'OK'};
			print "WARNING: " . $MOUNT . " is mounted! But type is not " . $TYPE . "\n";
			exit $ERRORS{'WARNING'};
	print "OK: " . $MOUNT . " is mounted!\n";
	exit $ERRORS{'OK'};

Appears to be working nicely during initial tests. YMMV…

Martin Scharm | Permalink |

Thanks for your efforts, I’ll upgrade my version! ;-)

qazerr | Permalink |

Hi. Thank you for this plugin. P.S. For getting this plugin work with SELnux you should set at least nagios_unconfined_plugin_exec_t type. for e.g.

semanage fcontext -a -s system_u -t nagios_unconfined_plugin_exec_t -f -- '/etc/nagios/plugins/check_mount.pl'

Sven | Permalink |

Thank you for this tiny but extremely useful script! Works like a charm for me and does what check_disk isn’t any use.

daehyung | Permalink |

Hello. First of all thank you for supplying very nice plugin though.

I’m the newbie of using nagios. I’d like to suggest you how about to change the line number 14 from use utils qw(%ERRORS); to use Nagios::Plugin qw(%ERRORS);

Development doc says that utils.pm is gonna deprecated soon or later.

Martin Scharm | Permalink |

Where did you read that utils.pm is going to be deprecated? The website of that perl module Nagios::Plugin links to the guidelines in which they recommend the usage of utils.pm .

Leave a comment

There are multiple options to leave a comment: