Batch script to launch the xml files from any folder

June 19, 2013 at 19:06:48
Specs: Windows XP
I need to create a generic batch script to launch the batch xml files from any folders and scheduling through windows task sheduler at predefined time.These batch xml files are from financial reporting studio and scheduleBatch.cmd is the inbuilt utility which calls these xml files when we run script. Below 1st batch script I have written for genric script(which launch a set of batch .xml files from any folder and scheduling it through windows task scheduler at a predefined time to run particular folder) and 2nd batch script which launches the batch xml files pointing to only Monthly daily weekly folder

My 1st scipts is not working properly as expected. Am I missing something! please help me out on what lines to be added to make it work as expected.

1) SET xml_dir=%1

SET hyp_server="server name"

For %%z in (%xml_dir%\*.xml) do schedulebatch %%z %hyp_server%
SET RC=%ERRORLEVEL%
EXIT /B %R C%
2) @echo off

SET SCRIPTLOG=\Batch.log

echo Frequency can be entered as Daily, Weekly and Monthly

set /p frq="Enter Frequency: " %=%

IF %frq% ==Daily (

echo Frequency is Daily > %SCRIPTLOG%

setlocal

for /l %%x in (1, 1, 1) do (

SET BATCHNUM=0%%x

call schedulebatch.bat !BATCHNUM:~-2!.xml

if !ERRORLEVEL! GEQ 1 (

echo Error scheduling FR_Daily_!BATCHNUM:~-2!.xml ......................... >> %SCRIPTLOG%

copy %SCRIPTLOG% <your error directory>\%~n0_%TODAY%.log
) else (

echo FR_Daily_!BATCHNUM:~-2!.xml scheduling was successful. >> %SCRIPTLOG%

)

)

setlocal DISABLEDELAYEDEXPANSION

) else (

IF %frq% ==Weekly (

echo Frequency is Weekly > %SCRIPTLOG%

setlocal ENABLEDELAYEDEXPANSION

for /l %%x in (1, 1, 1) do (

SET BATCHNUM=0%%x

call schedulebatch.bat !BATCHNUM:~-2!.xml

if !ERRORLEVEL! GEQ 1 (

echo Error scheduling FR_Weekly_!BATCHNUM:~-2!.xml ......................... >> %SCRIPTLOG%

copy %SCRIPTLOG% <your error directory>\%~n0_%TODAY%.log
) else (

echo FR_Weekly_!BATCHNUM:~-2!.xml scheduling was successful. >> %SCRIPTLOG%

)

)

setlocal DISABLEDELAYEDEXPANSION

) else (

IF %frq% ==Monthly (

echo Frequency is Monthly > %SCRIPTLOG%

setlocal ENABLEDELAYEDEXPANSION

for /l %%x in (1, 1, 1) do (

SET BATCHNUM=0%%x

call schedulebatch.bat !BATCHNUM:~-2!.xml

if !ERRORLEVEL! GEQ 1 (

echo Error scheduling FR_Monthly_!BATCHNUM:~-2!.xml ......................... >> %SCRIPTLOG%

copy %SCRIPTLOG% <your error directory>\%~n0_%TODAY%.log
) else (

echo FR_Monthly_!BATCHNUM:~-2!.xml scheduling was successful. >> %SCRIPTLOG%

)

)

setlocal DISABLEDELAYEDEXPANSION

) else (

echo Entered frequency does not match with the Batch Frequency

)

)

)


See More: Batch script to launch the xml files from any folder

Report •

#1
June 19, 2013 at 20:40:03
I can't see much wrong with script #1, but I don't know what input you are givng:
SET xml_dir=%1

If there are spaces anywhere in the path, you must use quotes and asterisk for all:
set xml_dir="%*"

In script #2, I would recommend strongly to remove all spaces, or use quotes:
IF %frq% ==Daily (

to either this:
if /i %frq%==daily (

but better yet:
if /i "%frq%" equ "daily" (

because you don't always know when that space might kill your comparison-test for equality. (f/e: "daily " does not equal "daily")


Report •

#2
June 20, 2013 at 07:27:45
.
--------------------------------------------------------------------------------

I really appreciate your help!
For the 1st script Let say there are n number of batch xml files that needs to be executed by the bat script and shedule these xml by windows task scheduler(daily monthly weekly) .How do i go about designing a script that will do the following:
1. executing a list of n nuber of files to run from that folder.
2. Do I need to pass any kind of parameters or set up any variables
3. If the execution is successful the next file in the order is executed automatically and so on and goes to script\success.log file .If it is failed it should goes to script\Failed.log file
how the error handling can be done to this script

Do i put the above inside a function and pass the files as arguments or do i go with loops. Please help me out , i'd be extremely grateful. Thanks in advance



Report •
Related Solutions


Ask Question