Reputation: 335
I have a batch file which I want to schedule to run. Bellow is the batch file.
@ECHO OFF
SET LOGFILE_DATE=%DATE:~4,2%.%DATE:~7,2%.%DATE:~10,4%
SET LOGFILE_TIME=%TIME:~0,2%.%TIME:~3,2%
SET LOGFILE="C:\N-able\Projects\AML\NDB_Bank\devinda\AML_Data_Auto-%LOGFILE_DATE%-%LOGFILE_TIME%.log"
call :Logit >> %LOGFILE%
exit /b 0
:Logit
set "firstLine"
for /f "tokens=*" %%A in (C:\AML_handshake.txt) do (
If not defined firstLine set "firstLine=%%A"
set Lastline=%%A
)
set "datevalue=%firstLine:~9,10%"
REM *** FIRST CHECK ***
if "EOF" NEQ "%Lastline%" goto fail
REM *** SECOND CHECK ***
set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "data=%dd%-%mm%-%yyyy%"
if "%data%" NEQ "%datevalue%" goto fail
goto prog
:prog
echo Incremental Data Extraction - Started
sqlplus -s ***@//**.**.**.**:****/*** @call_proc.sql
echo Incremental Data Extraction - Ended
echo Generating AML Files - Started
start "C:\Extractor" TableExtractor.exe
echo Generating AML Files - Ended
:fail
echo Process Completed
The AML_handshake.txt is transferred to the server at 4:00AM. And I schedule my job to run at 4:30AM. My question is for some reason the AML_handshake.txt file is not available at 4:00AM and the file transferred after 4:30AM, how is it possible to run my job from the scheduler? And the job should run only once with-in a day.
Upvotes: 0
Views: 36
Reputation: 4020
Throw this at the top of your file. It will check for the file and if it does not exist, waits 30 minutes or until input.
@ECHO OFF
:retest
if exist C:\AML_handshake.txt (
goto :validfile
) else (
Echo File does not exist
timeout 1800
goto :retest
)
:validfile
Entire code would look like this.
@ECHO OFF
:retest
if exist C:\AML_handshake.txt (
goto :validfile
) else (
Echo File does not exist
timeout 1800
goto :retest
)
:validfile
SET LOGFILE_DATE=%DATE:~4,2%.%DATE:~7,2%.%DATE:~10,4%
SET LOGFILE_TIME=%TIME:~0,2%.%TIME:~3,2%
SET LOGFILE="C:\N-able\Projects\AML\NDB_Bank\devinda\AML_Data_Auto-%LOGFILE_DATE%-%LOGFILE_TIME%.log"
call :Logit >> %LOGFILE%
exit /b 0
:Logit
set "firstLine"
for /f "tokens=*" %%A in (C:\AML_handshake.txt) do (
If not defined firstLine set "firstLine=%%A"
set Lastline=%%A
)
set "datevalue=%firstLine:~9,10%"
REM *** FIRST CHECK ***
if "EOF" NEQ "%Lastline%" goto fail
REM *** SECOND CHECK ***
set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "data=%dd%-%mm%-%yyyy%"
if "%data%" NEQ "%datevalue%" goto fail
goto prog
:prog
echo Incremental Data Extraction - Started
sqlplus -s ***@//**.**.**.**:****/*** @call_proc.sql
echo Incremental Data Extraction - Ended
echo Generating AML Files - Started
start "C:\Extractor" TableExtractor.exe
echo Generating AML Files - Ended
:fail
echo Process Completed
Upvotes: 1