check-blacklist.sh: Fix potential false positive
[mgsautils.git] / fs / check-nfs-hang.sh
1 #!/bin/sh
2
3 if [ $# -lt 1 ]
4 then
5 echo "Usage: $0 <fs> [email]"
6 echo "Where"
7 echo " fs - file system to check"
8 echo " email - send warning to specified e-mail address (print to stdout, if omitted)"
9 echo "Example: $0 /srv/remoteshare admin@cutekittens.tld"
10 exit 1
11 fi
12
13 make_command()
14 {
15 if [ -z "$1" ]
16 then
17 echo "cat"
18 else
19 echo "mail -s \"$subject\" $1"
20 fi
21 }
22
23 if ! mount | grep "on $1 type nfs" > /dev/null
24 then
25 subject="WARNING! Network file system ($1) on $(hostname) is not mounted!"
26
27 [ -z "$2" ] && echo "${subject}"
28 CMD=$(make_command "$2")
29 eval ${CMD} << EOT
30 This is to inform you that no NFS is mounted at $1.
31 Please investigate immediately!
32 EOT
33 exit 2
34
35 elif ! timeout 15 stat "$1" > /dev/null
36 then
37 subject="WARNING! Network file system ($1) on $(hostname) is hanging/unreachable!"
38
39 [ -z "$2" ] && echo "${subject}"
40 CMD=$(make_command "$2")
41 eval ${CMD} << EOT
42 This is to inform you that network share $1 is hanging/unreachable.
43
44 Mount details:
45
46 $(mount | grep "$1")
47
48 Please investigate immediately!
49 EOT
50 exit 3
51
52 fi