#! /bin/ash

ERROR=1
if [ "$2" != "" ]; then
  MESSAGE="$2"
else
  MESSAGE="Unknown event notification from CMC-TC Master unit $1!"
fi    
if [ "$1" != "" ]; then
  RECEIVER=`net -I $1 rpc info| grep "Domain Name" | cut -d ":" -f 2`
  if [ "$RECEIVER" != "" ]; then
    echo "Sending Message to $RECEIVER..."
    echo $MESSAGE | smbclient -I $1 -M $RECEIVER -U "Rittal CMC-TC Master"
    if [ "$?" = "0" ]; then
      ERROR=0
    fi 
  else
    echo "Message could not be sent."
  fi
else
  echo "IP-Address missing."
fi   
exit $ERROR 
