#!/bin/sh # Check for sharename on SMB with nagios # Michael Hodges 2011-03-04 # Modified version of check_smb by Dave Love REVISION=1.0 PROGNAME=`/bin/basename $0` PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` . $PROGPATH/utils.sh usage () { echo "\ Nagios plugin to check for SAMBA Share. Use anonymous login if username is not supplied. Usage: $PROGNAME -H -s <"sharename"> $PROGNAME -H -s <"sharename"> -u -p $PROGNAME --help $PROGNAME --version " } help () { print_revision $PROGNAME $REVISION echo; usage; echo; support } if [ $# -lt 1 ]; then usage exit $STATE_UNKNOWN fi username="guest" password="" 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";; -s) shift share="$1";; -u) shift username="$1";; -p) shift password="$1";; *) usage; exit $STATE_UNKNOWN;; esac shift done if [ "$username" = "guest" ]; then stdout=`smbclient -N -L "$host" 2>&1` sharetest=`echo "$stdout" | grep -o "$share" |head -n 1` else stdout=`smbclient -L "$host" -U"$username"%"$password" 2>&1 | sed 's/\n/
/'` sharetest=`echo "$stdout" | grep -o "$share" |head -n 1` fi if [ "$sharetest" = "$share" ]; then echo "SMB OK: $(echo "$stdout" | grep "$share" |head -n 1)" exit $STATE_OK else if [[ "$(grep -c "
")" -eq "1" ]]; then echo "SMB CRITICAL: $stdout" | sed 's/
//' else echo "SMB CRITICAL:
" echo "$stdout" fi exit $STATE_CRITICAL fi