This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcheck_mount
executable file
·49 lines (41 loc) · 1.69 KB
/
check_mount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Written by [email protected]
# 2011-05-04
#
# Nagios plugin that checks if a certain mount is really mounted and writable
#Bugfix: for some reason "cat /dev/urandom" takes ages on a precise machine, so limit the working set asap
#STRING=`cat /dev/urandom| tr -dc 'a-zA-Z' | fold -w 25 | head -n1`
STRING=`head -n8 /dev/urandom| tr -dc 'a-zA-Z' | fold -w 25 | head -n1`
if [ $# -eq "2" ]; then
CHECK=`awk '$2 == var' var=$1 /proc/mounts`
MOUNTPOINT=`echo $CHECK | cut -d' ' -f2`
MOUNTTYPE=`echo $CHECK | cut -d' ' -f3`
if [ "$MOUNTPOINT" == "$1" ]; then
if [ "$2" == "all" ]; then
echo -e "OK - $1 is mounted with type $MOUNTTYPE"
exit 0
elif [ "$MOUNTTYPE" == "$2" ]; then
cd $1 && touch $STRING
if [ $? -eq 0 ]; then
echo -e "OK - $1 is mounted with type $MOUNTTYPE and is writable"
rm $STRING
exit 0
else
echo -e "WARNING - $1 is mounted with type $MOUNTTYPE but is not writable"
exit 1
fi
else
echo -e "WARNING - $1 is mounted but with incorrect type ($MOUNTTYPE)"
exit 1
fi
else
echo -e "CRITICAL - $1 isn't mounted"
# try to mount as silent as possible
mount $1 2> /dev/null
exit 2
fi
else
echo "USAGE: $0 <mount point> <fstype>"
echo "Use <fstype> 'all' if the type doesn't matter - not checked if writable"
exit 1
fi