#!/bin/bash

TGT_HOST1="192.168.100.14"
TGT_HOST2="192.168.100.15"
FILE_SIZE_K=10
FILE_NAME="./test-file"
SHARE_NAME="share"
USER="ddiss"
PASS="password"

function _put
{
	local server=$1
	local rem_file=$2
	smbclient -U ${USER}%${PASS} //${server}/${SHARE_NAME} \
		  -c "put $FILE_NAME $rem_file" &> /dev/null \
		|| echo "FAILED put $rem_file"
}

function _del
{
	local server=$1
	local rem_file=$2
	smbclient -U ${USER}%${PASS} //${server}/${SHARE_NAME} \
		  -c "del $rem_file" &> /dev/null \
		|| echo "FAILED del $rem_file"
}

dd if=/dev/zero of=${FILE_NAME} bs=1K count=${FILE_SIZE_K}

while [ 1 ]; do
	echo "starting write jobs"
	for i in $(seq 55000 60000); do
		if [ 0 -eq $(( $i & 1 )) ]; then
			srv=$TGT_HOST1
		else
			srv=$TGT_HOST2
		fi
		_put "$srv" "test${i}\file${i}" &
		sleep 0.005 
	done

	echo "awaiting completion of write jobs before starting cleanup"
	wait

	sleep 5

	echo "starting removal jobs"
	for i in $(seq 55000 60000); do
		if [ 0 -eq $(( $i & 1 )) ]; then
			srv=$TGT_HOST2
		else
			srv=$TGT_HOST1
		fi
		_del "$srv" "test${i}\file${i}" &
		sleep 0.005 
	done

	echo "awaiting completion removal jobs"
	wait

	sleep 5
done
