#!/bin/bash
#-----------------------------------------------------------------------
# /var/install/bin/samba-winshook-netsend - send messages to wins clients
#
# Copyright (c) 2002-2013 Thomas Bork, tom(at)eisfair(dot)net
#
# Creation   : 2005-01-27 tb
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#-----------------------------------------------------------------------
if [ $# -lt 3 ]
then
   {
    echo "Usage: /var/install/bin/samba-winshook-netsend \"machine\" \"message\" \"delay\" \"log\" \"logfile\""
   } 1>&2
   exit 1
fi

name="$1"
message="$2"
delay="$3"
log="$4"
logfile="$5"
sleep "$delay"

/var/install/bin/samba-netsend "$name" "$message"
if [ $? -eq 0 ]
then
    if [ "$log" = "yes" ]
    then
        echo "`date +"%d.%m.%Y %H:%M:%S"`: Sending message to $name was successfull." >>"$logfile"
    fi
else
    if [ "$log" = "yes" ]
    then
        echo "`date +"%d.%m.%Y %H:%M:%S"`: Sending message to $name was not successfull!" >>"$logfile"
    fi
fi

exit 0
