I'm trying to execute couple of commands for a particular file extensions in a for loop. For loop is not working properly in below script, sometimes it is triggering below commands properly for the two files ECI_Jobs.dsx,PHP_Jobs.dsx and sometimes its triggering the commands twice for the same file and not triggering any commands for the other file
commands
SET DParams= /D=%HostName% /H=%ServerName% /U=%userid% /P=%password% %project%
%DSImportCMD% %DParams% %DSExportFileName% >> %LogFileName%
Code: Select all
echo off
:: Setting the Datastage commands
SET DSImportCMD="C:\IBM\InformationServer\Clients\Classic\dscmdimport.exe"
Set HostName=%1:9080
Set ServerName=%1
set userid=%2
set password=%3
set project=%4
REM =====Below %~f0 will provide obsolute path with filename
for /F %%i in ("%~f0") do set filename=%%~ni
REM ====== Below command will provide the current date with format YYYYMMDD_HH_MM_SS
SET CurrentDate=%date:~-4,4%%date:~-10,2%%date:~-7,2%
SET hh=%time:~-11,2%
if %hh%==0 set hh=00
if %hh%==1 set hh=01
if %hh%==2 set hh=02
if %hh%==3 set hh=03
if %hh%==4 set hh=04
if %hh%==5 set hh=05
if %hh%==6 set hh=06
if %hh%==7 set hh=07
if %hh%==8 set hh=08
if %hh%==9 set hh=09
SET mm=%time:~-8,2%
SET ss=%time:~-5,2%
REM ===Below command will echo file name with batch script name appended with timestamp
REM ===echo %filename%_%CurrentDate%_%hh%_%mm%_%ss%.log
REM ===Below commmand willl provide the directory name from where the script is triggered
for %%F in ("%~f0") do set dirname=%%~dpF
SET basedirname=%dirname%
SET resultdir=Result\
SET Currentdir=Current\
SET LogFileName=%basedirname%%resultdir%%filename%_%CurrentDate%_%hh%_%mm%_%ss%.log
REM =====ECHO %basedirname%%resultdir%%filename%_%CurrentDate%_%hh%_%mm%_%ss%.log
:: Checking Number of Arguments are passed to the script
IF NOT "%5"=="" (
echo No more than four arguments, please check the arguments >> %LogFileName%
goto :EOF
)
if "%1"=="" (
echo please check the arguments, script expects 4 arguments >> %LogFileName%
goto :EOF
)
if "%2"=="" (
echo please check the arguments, script expects 4 arguments >> %LogFileName%
goto :EOF
)
if "%3"=="" (
echo please check the arguments, script expects 4 arguments >> %LogFileName%
goto :EOF
)
if "%4"=="" (
echo please check the arguments, script expects 4 arguments >> %LogFileName%
goto :EOF
)
:: Below cnt will provide the number of files in the Current directory
set count=0
cd %basedirname%%Currentdir%
set cnt=0
for %%A in (*.dsx) do set /a cnt+=1
cd %basedirname%
Set IntCount=0
IF %cnt% GTR %IntCount% Goto dsimpcmp
ECHO Great! You don't have any files to process.
GOTO :EOF
:dsimpcmp
for %%F in (%basedirname%%Currentdir%*.dsx) do (
SET DSExportFileName=%%F
::echo %DSExportFileName%
::echo %HostName%
::echo %ServerName%
::echo %userid%
::echo %password%
::echo %project%
SET DParams= /D=%HostName% /H=%ServerName% /U=%userid% /P=%password% %project%
%DSImportCMD% %DParams% %DSExportFileName% >> %LogFileName%
)
GOTO :EOF
Thanks,
Raju