-
Notifications
You must be signed in to change notification settings - Fork 18
/
check_smb
executable file
·61 lines (50 loc) · 1.06 KB
/
check_smb
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
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
# Check anon access to SMB for nagios.
# Dave Love <[email protected]>, 2005-07-15
REVISION=1.0
PROGNAME=`/usr/bin/basename $0`
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
usage () {
echo "\
Nagios plugin to check if (anonymous) access to SMB on host works.
Usage:
$PROGNAME -H <host>
$PROGNAME --help
$PROGNAME --version
"
}
help () {
print_revision $PROGNAME $REVISION
echo; usage; echo; support
}
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
usage
exit $STATE_UNKNOWN
fi
while test -n "$1"; do
case "$1" in
--help | -h)
help
exit $STATE_OK;;
--version | -V)
print_revision $PROGNAME $REVISION
exit $STATE_OK;;
-H)
shift
host=$1;;
*)
usage; exit $STATE_UNKNOWN;;
esac
shift
done
stdout=`/usr/bin/smbclient -U guest -N -L "$host" 2>&1`
if [ $? -eq 0 ]; then
header=`echo "$stdout" | grep Server= | head -n 1`
echo "OK $header"
exit $STATE_OK
else
err=`echo "$stdout" | head -n 1`
echo "CRITICAL SMB anon access: $err"
exit $STATE_CRITICAL
fi