Track progress of multiple start commands in a batch file

  batch-file, command, windows

Below is the script which does copy of data from tables, and as there are many tables to be copied so i want them to run in parallel. And this master batch job below (master_copy.bat) is executed from task scheduler.

cd "I:Copy_Scripts"

start CopyTables.bat Table1
timeout /t 10 /nobreak

start CopyTables.bat Table2 Table3 
timeout /t 10 /nobreak

start CopyTables.bat Table4 Table5 Table6 Table7
timeout /t 10 /nobreak

start CopyTables.bat Table8 Table9 Table10 Table11 Table12
timeout /t 10 /nobreak

start CopyTables.bat Table13 Table14 Table15 Table16 Table17 Table18
timeout /t 10 /nobreak

Now,

We can not track the progress, as the task scheduler job status is not in Running.
Job just creates 5 log files (as per CopyTables.bat) from above script and status changes to ready.
I tried adding /WAIT for each start, and that defeats the purpose of parallel runs as it waits for the first start cmd to end before starting 2nd.

copytables.bat does a bcp out and bcp in to tables, and writes to the log

How can the script be modified and what to add here? Thanks

Below is the copy tables script

REM This script to test multiple files with for loop

::Set log folder path
SET LOG_FOLDER_PATH=I:logs
SET FOLDER_DATE=%date:~10%%date:~4,2%%date:~7,2%

::Sets the proper date and time stamp with 24Hr Time for log file naming convention
SET HOUR=%time:~0,2%
SET dtStamp9=%date:~-4%%date:~4,2%%date:~7,2%_0%time:~1,1%%time:~3,2%%time:~6,2% 
SET dtStamp24=%date:~-4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%

IF "%HOUR:~0,1%" == " " (SET dtStamp=%dtStamp9%) else (SET dtStamp=%dtStamp24%)

::Creating new log directory every day
SET LOG_FOLDER=%LOG_FOLDER_PATH%%FOLDER_DATE%
IF NOT EXIST "%LOG_FOLDER%" (MD %LOG_FOLDER%)

SET LOGFILE=%LOG_FOLDER%Copy_%FOLDER_DATE%_%dtStamp%.txt
ECHO %LOGFILE%

SET SRC_BCP_FOLDER=%LOG_FOLDER%SRC_BCP_OUT_%FOLDER_DATE%
IF NOT EXIST "%SRC_BCP_FOLDER%" (MD %SRC_BCP_FOLDER%)

@echo Log File Location : %LOGFILE%
@echo:

ECHO Arguments passed were: %*

::Call the copy script

FOR %%I IN (%*) DO ( 

ECHO %%I

CALL :CopyTables %%I>> %LOGFILE% 2>&1

TYPE %LOGFILE% )

EXIT /B 0

:CopyTables

@echo Log File Location : %LOGFILE%
@echo:
@echo Copy Script Started For %1 : %date% %time%
@echo:

@echo :: Step1: BCP Out from Source..%1 &@echo Start Time: %date% %time% &@echo:

ECHO %1

<bcp out command>

@echo:
IF %ERRORLEVEL%==0 (
ECHO Proceeding with table truncate
) ELSE (
ECHO "Errors encountered during execution.  Exited with status: %errorlevel%"
GOTO :SendMail
)

@echo :: Step 1: BCP Out from Source..%1 &@echo End Time: %date% %time% &@echo:
@echo:
@echo :: Step 2: Truncate Table %1  &@echo Start Time: %date% %time%&@echo:

<truncate command>

IF %ERRORLEVEL%==0 (
ECHO Proceeding with table bcp in for target.%1
) ELSE (
ECHO "Errors encountered during execution.  Exited with status: %errorlevel%"
GOTO :SendMail
)

@echo :: Step 2: Truncate Table target.%1  &@echo End Time: %date% %time%&@echo:
@echo:
@echo :: Step 3: BCP IN %1  to targetdb &@echo Start Time: %date% %time%&@echo:

<bcp in command>

IF %ERRORLEVEL%==0 (
ECHO bcp in ended for targetdb.%1
) ELSE (
ECHO "Errors encountered during execution.  Exited with status: %errorlevel%"
GOTO :SendMail
)
@echo :: Step 3: BCP IN %1  to targetdb &@echo End Time: %date% %time%&@echo:
@echo:
@echo Copy Script Ended For %1 : %date% %time%
@echo:
@echo ===========================================================================================
@echo:
EXIT /B 0

:SendMail
@echo Sending Mail
<mail code>

Source: Windows Questions

LEAVE A COMMENT