#!/bin/bash # #*************************************************************************** # SYCOR GmBh #*************************************************************************** # # Filename : %M% # Version : %I% # Authors : Peter Braack # Creation Date : 01-Mar-2006 # Last modified : 24.03.2013 # # Abstract # Write and Readtest on Shares # # Working Dir: LASTDIR # # History # Date | Authors | Description # --------+-------------+-------------------------------------------------- # | | #*************************************************************************** # # 1.3.2008 # Modified by Jan Paul - edited to allow empty spaces in share names and fixed return # values so error in writing produces critical state of service and english text in $STING variable # # 24.3.2013 # Extended by Bernhard Neumann to allow writing to a subdir relative to SHARE. # The subdir must exists, otherwise a warning state is returned to nagios # # Parameters HOSTNAME=$1 SHARE=$2 SMB_DIR=$3 WORKGROUP=$4 TESTFILE=$1_$$ RESPFILE=RESP_$1_$$ cd /tmp echo $(/bin/date) >> $TESTFILE echo "Nagios Writetest from $(/bin/hostname)" >> $TESTFILE echo "Hostname $HOSTNAME" >> $TESTFILE echo "Share $SHARE" >> $TESTFILE echo "Subdir $SMB_DIR" >> $TESTFILE # Settings RET=0 STRING="Writing to $SHARE/$SMB_DIR on $HOSTNAME OK" FAILSTRING="ERROR writing to share $SHARE/$SMB_DIR on $HOSTNAME." WARNSTRING="WARNING - Directory $SMB_DIR on $HOSTNAME/$SHARE does not exist" SMBCLIENT="/usr/bin/smbclient -A /etc/nagios2/conf.d/share1.pw -W $WORKGROUP" # # check for subdir and put testfile from Server with smbclient # $SMBCLIENT //$HOSTNAME/$SHARE -c "cd $SMB_DIR " 2> /dev/null 1> /dev/null if [ "$?" -ne "0" ]; then RET="1" STRING=$WARNSTRING; /bin/rm -f $TESTFILE else # now put file to server, get it back and compare # $SMBCLIENT //$HOSTNAME/$SHARE -c "cd $SMB_DIR ;put $TESTFILE" 2> /dev/null 1> /dev/null # # get testfile from Server with smbclient # $SMBCLIENT "//$HOSTNAME/$SHARE" -c "cd $SMB_DIR ; get $TESTFILE $RESPFILE" 2> /dev/null 1> /dev/null # # Gesendetes und empfangenes File vergleichen # /usr/bin/diff -a $TESTFILE $RESPFILE > /dev/null 2>&1 if [ "$?" -eq 0 ]; then RET=0; else RET=2; STRING=$FAILSTRING; fi # # Aufrauemen # # # delete testfile from Server with smbclient # $SMBCLIENT "//$HOSTNAME/$SHARE" -c "cd $SMB_DIR ;del $TESTFILE" 2> /dev/null 1> /dev/null /bin/rm -f $RESPFILE /bin/rm -f $TESTFILE fi # # Returnwert und Text ausgeben # echo $STRING exit $RET