From: MegaBrutal Date: Sat, 5 Nov 2016 22:20:40 +0000 (+0100) Subject: check-nfs-hang.sh: Added script to monitor NFS mount health X-Git-Url: http://git.megabrutal.com/?p=mgsautils.git;a=commitdiff_plain;h=076ff6605e618e3bf0fdb0bd9f9f6df56f7b35e4 check-nfs-hang.sh: Added script to monitor NFS mount health The check-nfs-hang.sh script alerts when the monitored network file system is not mounted or hanging. Similarly to check-fs-usage.sh, it may be scheduled with cron, and sends e-mail when an e-mail address is supplied. By the way, check-fs-usage.sh has been moved to the more appropriate "fs" directory. renamed: host/check-fs-usage.sh -> fs/check-fs-usage.sh new file: fs/check-nfs-hang.sh --- diff --git a/fs/check-fs-usage.sh b/fs/check-fs-usage.sh new file mode 100755 index 0000000..3b7cd8d --- /dev/null +++ b/fs/check-fs-usage.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +if [ $# -lt 2 ] +then + echo "Usage: $0 [email]" + echo "Where" + echo " fs - file system to check" + echo " percentage - acceptable file system usage treshold" + echo " email - send warning to specified e-mail address (print to stdout, if omitted)" + echo "Example: $0 / 95 admin@cutekittens.tld" + exit +fi + +if [ $(df -m $1 | sed 1d | awk '{print $5}' | sed "s/%//") -ge $2 ] +then + subject="WARNING! File system usage ($1) on $(hostname) is higher than $2 percent!" + if [ -z "$3" ] + then + echo ${subject} + df -m + else + df -m | mail -s "${subject}" $3 + fi +fi diff --git a/fs/check-nfs-hang.sh b/fs/check-nfs-hang.sh new file mode 100755 index 0000000..f50cc85 --- /dev/null +++ b/fs/check-nfs-hang.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +if [ $# -lt 1 ] +then + echo "Usage: $0 [email]" + echo "Where" + echo " fs - file system to check" + echo " email - send warning to specified e-mail address (print to stdout, if omitted)" + echo "Example: $0 /srv/remoteshare admin@cutekittens.tld" + exit 1 +fi + +make_command() +{ + if [ -z "$1" ] + then + echo "cat" + else + echo "mail -s \"$subject\" $1" + fi +} + +if ! mount | grep "on $1 type nfs" > /dev/null +then + subject="WARNING! Network file system ($1) on $(hostname) is not mounted!" + + [ -z "$2" ] && echo "${subject}" + CMD=$(make_command "$2") + eval ${CMD} << EOT +This is to inform you that no NFS is mounted at $1. +Please investigate immediately! +EOT +exit 2 + +elif ! timeout 15 stat "$1" > /dev/null +then + subject="WARNING! Network file system ($1) on $(hostname) is hanging/unreachable!" + + [ -z "$2" ] && echo "${subject}" + CMD=$(make_command "$2") + eval ${CMD} << EOT +This is to inform you that network share $1 is hanging/unreachable. + +Mount details: + +$(mount | grep "$1") + +Please investigate immediately! +EOT +exit 3 + +fi diff --git a/host/check-fs-usage.sh b/host/check-fs-usage.sh deleted file mode 100755 index 3b7cd8d..0000000 --- a/host/check-fs-usage.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -if [ $# -lt 2 ] -then - echo "Usage: $0 [email]" - echo "Where" - echo " fs - file system to check" - echo " percentage - acceptable file system usage treshold" - echo " email - send warning to specified e-mail address (print to stdout, if omitted)" - echo "Example: $0 / 95 admin@cutekittens.tld" - exit -fi - -if [ $(df -m $1 | sed 1d | awk '{print $5}' | sed "s/%//") -ge $2 ] -then - subject="WARNING! File system usage ($1) on $(hostname) is higher than $2 percent!" - if [ -z "$3" ] - then - echo ${subject} - df -m - else - df -m | mail -s "${subject}" $3 - fi -fi