[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Antwort: [hobbit] Monitor CIFS mount on Linux client?



Hi

> I can exclude CIFS using df options to avoid the hang, but then I won't
> get any warning at all unless I find a better way to check the mounts. 
> Suggestions?
I have written an SMB test for Hobbit a few years ago, maybe this is what 
you are looking for.
It writes a small file to a CIFS share, reads it and then deletes it using 
the smbclient program.

Thorsten


#!/bin/sh
##########################################################################################
#  Hier geschieht der eigentliche Samba Test
##########################################################################################
SmbTest ( ) {
  echo "Samba test on $MACHINE" >$TEMPFILE
  grep -i $MACHINE $BBHOME/etc/smb.ini | while read mach user passw share
  do
    if [ "$mach" <> "#" ]
    then
    echo "This is a hobbit testfile and should be here only temporarely" 
>${TEMPFILE}1.txt
    error=`smbclient //$mach/$share -U $user $passw 2>&1 <<EOF
put ${TEMPFILE}1.txt testfile.txt
get testfile.txt ${TEMPFILE}2.txt
quit
EOF`
    echo "$error" | grep -i "ERR" >/dev/null
    if [ $? -ne 0 ]
    then
      echo "&green Samba test on //$mach/$share is ok"  >>$TEMPFILE
    else
      echo "&red Samba test on //$mach/$share failed" >>$TEMPFILE
      echo "$error" >>$TEMPFILE
    fi
    rm  ${TEMPFILE}1.txt ${TEMPFILE}2.txt >/dev/null 2>&1
fi
  done
  grep "&red" $TEMPFILE  >/dev/null
  if [ $? -eq 0 ]
  then
    COLOR=red
  fi
  return 0
}

##########################################################################################
#
#  Hier beginnt das Hauptprogramm
#
##########################################################################################

DEBUG=FALSE
if [ "$1." = "--debug." ]
then
   DEBUG=TRUE
   BBHOME=..
   . $BBHOME/etc/hobbitserver.cfg
   echo "Debugmode"
fi

BBHTAG=smb      # What we put in bb-hosts to trigger this test
COLUMN=$BBHTAG  # Name of the column, often same as tag in bb-hosts

TEMPFILE=$BBTMP/$BBHTAG.output.tmp

$BBHOME/bin/bbhostgrep $BBHTAG | while read L
do
  rm $TEMPFILE >/dev/null 2>&1
  set $L        # To get one line of output from bbhostgrep

  HOSTIP="$1"
  MACHINEDOTS="$2"
  MACHINE=`echo $2 | $SED -e's/\./,/g'`

  COLOR=green
  echo "Samba Test on $MACHINEDOTS" > $TEMPFILE
  SmbTest $2
  MSG=`cat $TEMPFILE`

  if [ $DEBUG = TRUE ]
  then
    echo "status $MACHINE.$COLUMN $COLOR `date` $MSG"
  else
    $BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date` $MSG"
  fi
  rm $TEMPFILE >/dev/null 2>&1
done

exit 0


smb.ini:

#
# Config file for the smb fileserver test (smb)
# for each fileshare which should be tested we need a line giving the 
servername and a sharename including testfile
#
# Host     User      Passw     Sharename
hostname   userID    Password  my_share      # this will test 
\\hostname\myshare with UserID "userID" and password "Password"



If you are not the intended addressee, please inform us immediately that you have received this e-mail in error, and delete it. We thank you for your cooperation.