Skip to content

Instantly share code, notes, and snippets.

@kurtraschke
Created December 23, 2010 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtraschke/753200 to your computer and use it in GitHub Desktop.
Save kurtraschke/753200 to your computer and use it in GitHub Desktop.
Big Brother (bb4.com) script for monitoring SMB servers
#!/bin/sh
#set -x
#
###################################################################
# smb.sh Charles Gillanders charles.gillanders@toucan.ie
# Modified by Kurt Raschke <kurt@kurtraschke.com>:
# No longer requires a valid user/pass for each machine
# Minor bug-fixing; better handling of the "dialup" and "nonetpage" directives
#
# A Big Brother External Script
# Monitors SMB fileshare services
#
# Sections ripped shamelessly from bb-network.sh and other sources
# Thanks to Sean et all for making Big Brother the tool it is.
#
###################################################################
#
# Requirements:
#
# A working copy of smbclient from the samba distribution, the
# full set of samba does not need to be running on your BBDISPLAY
# system but it must have access to the smbclient program and a
# suitable smb.conf configuration file.
#
# Instructions:
#
# Modify SMBCLIENT to point to your copy of the smbclient program
#
# For each host that has shares you want to monitor modify the
# bb-hosts file as appropriate, the correct syntax is "smb"
# i.e.
# 192.186.200.40 Host1 # dns smtp smb
#
# Modify $BBHOME/runbb.sh to include smb.sh in the BBEXT variable
# stop and restart BB.
#
###################################################################
#
# Test that bbhome is set and that the standard definitions are available
#
SMBCLIENT="/usr/bin/smbclient"
if test ! "$BBHOME"
then
echo "Error BBHOME is not set"
exit
else
if test ! "$BBTMP"
then
. $BBHOME/etc/bbdef.sh
fi
fi
#
# do the tests
#
$GREP "^[0-9]" $BBHOSTS |
while read linein
do
set $linein
HOSTIP=$1
FULLNAME=$2
IPADDR=`echo $1 | $SED "s/\.//g"`
set $linein # GET ALL THE LINE ARGS
shift; shift; # SKIP THE IP-ADDR AND NAME
if [ "$#" -ne 0 ]
then
newline=""
smbarg=""
# REWRITE THE ARGUMENTS SUCH THAT smb DIRECTIVES ARE BUNCHED TOGETHER
while [ "$#" -ne 0 ]
do
case $1
in
smb* )
if [ "$smbarg" = "" ]
then
smbarg="$1"
else
smbarg="${smbarg}|${1}"
fi
;;
* )
newline="$newline $1"
;;
esac
shift
done
set $newline $smbarg
fi
# As long as we have args
while test "$1"
do
line="$*" # Save this
case $1
in
*!* )
arg=`echo $1 | $SED 's/!//g'`
TESTREVERSED=TRUE
;;
*)
arg=$1
TESTREVERSED=FALSE
;;
esac
case $arg
in
#
# smb test
#
smb* )
dnme=$FULLNAME
fnme=`echo $FULLNAME | $SED -e 's/\./\,/g'`
FULLNAME=$fnme
OUTFILE="$BBTMP/smb.$FULLNAME"
OLDIFS=$IFS
IFS='|'
set $arg
IFS=$OLDIFS
SHARES=$*
COLOR="green"
LINE=""
if
$SMBCLIENT -N -L $HOSTIP > $OUTFILE 2>&1
then
TMPLINE="$FULLNAME - SMB Services Up :
`cat $OUTFILE`"
COLOR="green"
else
if
$BBHOME/bin/bbnet $dnme:139 >> $OUTFILE 2>&1
then
TMPLINE="$FULLNAME - Connection Fault (SMB port open, no server running) :
`cat $OUTFILE`"
COLOR="yellow"
else
TMPLINE="$FULLNAME - Connection Fault (SMB port closed, no server running) :
`cat $OUTFILE`"
COLOR="red"
fi
fi
LINE=$TMPLINE
if
echo "$NONETPAGE" | $GREP "smb" > /dev/null 2>&1
then
if [ "$COLOR" = "red" ]
then
COLOR="yellow"
fi
LINE="&yellow $TMPLINE (configured not to page)"
fi
if
echo "$linein" | $GREP "dialup" > /dev/null 2>&1
then
if [ "$COLOR" = "red" ]
then
COLOR="clear"
fi
LINE="&clear $TMPLINE (no page on dialup)"
fi
$BB $BBDISP "status ${FULLNAME}.smb $COLOR `date` $LINE"
;;
* )
;;
esac
set $line
shift;
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment