#!/bin/bash # check_mounted - plugin for nagios to check that a partition is mounted # # Based on check_glusterfs_mount by Ioannis Aslanidis and modified by Thomas Blanchin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. timelimit=5 # We allow 10 seconds for ls to rn. If it does not, we consider it has hanged. ### NOT NECESSARY AS ALL PARAMETERS ARE PATH TO CHECK #TOTALPARAMS=1 # Total number of expected parameters. minlines=2 # If we find less that these number of lines, we understand that there was an error. error=0 TryList() { # The path to check. path=${1} # List the contents of the path and verify that the output is correct numlines=$(/bin/ls -l ${path} | /usr/bin/wc -l) if [ ${numlines} -lt ${minlines} ]; then error=2 fi } TimerOn() { /bin/sleep ${timelimit} && /usr/bin/kill -s 14 ${$} & # Waits some seconds, then sends sigalarm to script. } Int14Vector() { echo CRITICAL: Mount point does not seem to work. Could not list the contents! exit 2 } # Timer interrupt (14) subverted for our purposes. trap Int14Vector 14 ### NOT NECESSARY AS ALL PARAMETERS ARE PATH TO CHECK # Check that the total number of parameters is correct. #if [ ${#} -ne ${TOTALPARAMS} ]; then # echo UNKNOWN: Script was executed with incorrect number of arguments. Check could not be performed. # exit 3 #fi # Start the timer. TimerOn # Make the call. for i in $* do TryList ${i} done # Kill the alarm timer, we do not need it any more. (bash will write to stdout about the process that got killed, redirecting makes no sense here) /usr/bin/kill ${!} if [ $error -eq 2 ]; then # HoHooooo echo CRITICAL: Mount point is not working correctly. exit 2 elif [ $error -eq 0 ]; then # Return success. echo OK: Mount seems to be working correctly exit 0 fi