So I have a for loop that does an iteration of a SQL stored procedure for every line in a file queue.txt, now that all works great, what DOESNT however is that if i
Okay so the soultion to my problem that I worked out was to add an extra batch file called co-ordinator.bat it checked if busy.txt was present, if it was then it would add the connecting devices into a file late.txt at the end of each iteration of the loop the process would check for the presence of late.txt, if it was present then it would merge it with queue.txt and then use a goto out of the loop to the top to re-initialise the for loop.
Code as such:
@echo off
cd "%UserProfile%\Desktop\Scripting\"
echo words > busy.txt
:rerun
FOR /f "delims=" %%a in ('type queue.txt') DO (
IF NOT EXIST reset.sql (
::Create SQL command
echo USE dbname> reset.sql
echo EXEC dbo.sp_ResetSubscription @ClientName = '%%a'>> reset.sql
echo EXEC dbo.sp_RunClientSnapshot @ClientName = '%%a'>> reset.sql
echo #################### %date% - %time% ####################################################>> log.txt
echo Reinitialising '%%a'>> log.txt
sqlcmd -i "reset.sql">> log.txt
echo. >> log.txt
echo ####################################################################################################>> log.txt
echo. >> log.txt
type queue.txt | findstr /v %%a> new.txt
type new.txt> queue.txt
echo New list of laptops waiting:>> log.txt
type queue.txt>> log.txt
echo. >> log.txt
echo ####################################################################################################>> log.txt
echo. >> log.txt
if exist reset.sql del /f /q reset.sql
if exist late.txt (
type late.txt>> queue.txt
del /f /q late.txt
goto rerun
)
)
)
if exist late.txt del /f /q late.txt
if exist busy.txt del /f /q busy.txt
if exist queue.txt del /f /q queue.txt
if exist new.txt del /f /q new.txt