WFM Script
Doesn't include the SQL
FOR /F "TOKENS=1 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET dd=%%A FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B FOR /F "TOKENS=1,2,3 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET yyyy=%%C REM Set Date to Today SET mydate-ymd=%yyyy%%mm%%dd% SET /A yy=%yyyy%-2000 SET mydate-dmy=%dd%%mm%%yy% REM ========= SET DIRECTORY HERE ============== SET mylocalpath=C:\X-Support\SheduledTask\Daily\ SET mypath=\\server\blah SET myfilename=filename_%mydate-dmy%.txt SET mytempfile=%mylocalpath%\temp-file.txt SET mylogfile=mylogfile.log REM Get start time: FOR /F "tokens=1-4 delims=:.," %%a in ("%time%") do (set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100") SET mystarttime=%time% echo doing something.... echo. rem call your SQL SET myendextracttime=%time% findstr ";" %mytempfile% >>%mylocalpath%\%myfilename% rem Get end time: for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100") set myendtime=%time% rem Get elapsed time: set /A elapsed=end-start set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100 if %mm% lss 10 set mm=0%mm% if %ss% lss 10 set ss=0%ss% if %cc% lss 10 set cc=0%cc% set myelapsedtime=%hh%:%mm%:%ss%,%cc% copy %mylocalpath%\%myfilename% %mypath%\Backup\%myfilename% copy %mylocalpath%\%myfilename% %mypath%\Daily\%myfilename% copy %mylocalpath%\%myfilename% %mylocalpath%\SEIA-last-extract.txt del %mylocalpath%\%myfilename% echo ERRORLEVEL: %errorlevel% IF "%errorlevel%"=="0" goto success goto fail :success echo Success! echo. >> %mypath%\Log\%mylogfile% echo Log Entry : %time% %date%>> %mypath%\Log\%mylogfile% echo. >>%mypath%\Log\%mylogfile% findstr "rows" %mytempfile% >>%mypath%\Log\%mylogfile% echo Extract start time: %date% %mystarttime% >> %mypath%\Log\%mylogfile% echo Extract end time: %date% %myendtime% >> %mypath%\Log\%mylogfile% echo Extract duration: %myelapsedtime% >> %mypath%\Log\%mylogfile% echo ------------------------------->> %mypath%\Log\%mylogfile% goto end :fail echo Fail on Copy !!! echo. >> %mypath%\Log\%mylogfile% echo Log Entry : %time% %date%>> %mypath%\Log\%mylogfile% echo. >>%mypath%\Log\%mylogfile% echo :Extract FAILED >>%mypath%\Log\%mylogfile% findstr "rows" %mytempfile% >>%mypath%\Log\%mylogfile% echo Extract start time: %date% %mystarttime% >> %mypath%\Log\%mylogfile% echo Extract end time: %date% %myendtime% >> %mypath%\Log\%mylogfile% echo Extract duration: %myelapsedtime% >> %mypath%\Log\%mylogfile% echo ------------------------------->> %mypath%\Log\%mylogfile% goto end :end echo Pausing for 10 seconds before exiting... ping -n 10 127.0.0.1>NUL