for loop to trigger commands for each .dsx file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
somu_june
Posts: 30
Joined: 19 Jun 2013 20:26

for loop to trigger commands for each .dsx file

#1 Post by somu_june » 26 Jun 2013 14:37

Hi,

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

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#2 Post by Squashman » 26 Jun 2013 14:49

Again! Redundant code! No need to have a For Loop to count the number of DSX files and then have a FOR Loop to process them. I see you haven't taken any of my advice in your previous thread either.

You also only need to check %4 %5. The others are redundant.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#3 Post by Squashman » 26 Jun 2013 14:59

Get RID of the Double colon echo commands inside your for loop. That is bad coding.
Don't assign your loop variable to another variable. Just use it as %%F in your execution command.
If you want to use the DPARMS variable like that then you need to use DelayedExpansion. But I would just list all the variables in your execution command and get rid of DPARMS. Or set your DPARMS variable before the FOR LOOP.

somu_june
Posts: 30
Joined: 19 Jun 2013 20:26

Re: for loop to trigger commands for each .dsx file

#4 Post by somu_june » 26 Jun 2013 15:07

Squashman,

I have taken your advice from previous post. I'm modifying the code and I sent you the old code that I have in other file. Here is the latest code with the changes you mentioned in the previous post.

Code: Select all

:: ====================Written by Somaraju Buddharaju================================================================
:: ===========This script will loop through the .dsx files under Current directory and ======================
:: ========== imports the Datastage jobs and compiles the jobs if compile option is passed====================
:: ========== Script expects 5 input parameters 1.HostName like "INFETLD01, 2.userid : Datastage userid=======
::=========== 3.password: Datastage password, 4.project : Datastage project name like "CPT_DEV" ==============
::=========== 5. dscmp : Datastage compile option like "C" for compile and "N" for Not compile ===============
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
set dscmp=%5

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 "%6"=="" (
    echo No more than four arguments, please check the arguments >> %LogFileName%
    goto :EOF
)
if  "%5"=="" (
    echo please check the arguments, script expects 5 arguments >> %LogFileName%
   goto :EOF
)
:: Below exist command checks if .dsx file exists in the Current directory
cd %basedirname%%Currentdir%
IF EXIST "*.dsx" GOTO dsimpcmp
ECHO Great! You don't have any files to process.
cd %basedirname%
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%
cd %basedirname%
)
GOTO :EOF


Thanks,
Raju

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#5 Post by Squashman » 26 Jun 2013 15:09

somu_june wrote:Squashman,

I have taken your advice from previous post. I'm modifying the code and I sent you the old code that I have in other file. Here is the latest code with the changes you mentioned in the previous post.

Code: Select all

:: ====================Written by Somaraju Buddharaju================================================================
:: ===========This script will loop through the .dsx files under Current directory and ======================
:: ========== imports the Datastage jobs and compiles the jobs if compile option is passed====================
:: ========== Script expects 5 input parameters 1.HostName like "INFETLD01, 2.userid : Datastage userid=======
::=========== 3.password: Datastage password, 4.project : Datastage project name like "CPT_DEV" ==============
::=========== 5. dscmp : Datastage compile option like "C" for compile and "N" for Not compile ===============
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
set dscmp=%5

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 "%6"=="" (
    echo No more than four arguments, please check the arguments >> %LogFileName%
    goto :EOF
)
if  "%5"=="" (
    echo please check the arguments, script expects 5 arguments >> %LogFileName%
   goto :EOF
)
:: Below exist command checks if .dsx file exists in the Current directory
cd %basedirname%%Currentdir%
IF EXIST "*.dsx" GOTO dsimpcmp
ECHO Great! You don't have any files to process.
cd %basedirname%
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%
cd %basedirname%
)
GOTO :EOF


Thanks,
Raju


Looks the same to me. Reread your previous thread and then reread all the comments I made in this thread.

somu_june
Posts: 30
Joined: 19 Jun 2013 20:26

Re: for loop to trigger commands for each .dsx file

#6 Post by somu_june » 26 Jun 2013 15:22

Hi Squashman,

I think we posted messages on same time and your message is few minutes ahead of mine. Here is my latest code, and I did modify according to your comments, thanks for helping me and this working now.

Code: Select all

:: ====================Written by Somaraju Buddharaju================================================================
:: ===========This script will loop through the .dsx files under Current directory and ======================
:: ========== imports the Datastage jobs and compiles the jobs if compile option is passed====================
:: ========== Script expects 5 input parameters 1.HostName like "INFETLD01, 2.userid : Datastage userid=======
::=========== 3.password: Datastage password, 4.project : Datastage project name like "CPT_DEV" ==============
::=========== 5. dscmp : Datastage compile option like "C" for compile and "N" for Not compile ===============
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
set dscmp=%5

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 "%6"=="" (
    echo No more than four arguments, please check the arguments >> %LogFileName%
    goto :EOF
)
if  "%5"=="" (
    echo please check the arguments, script expects 5 arguments >> %LogFileName%
   goto :EOF
)
:: Below exist command checks if .dsx file exists in the Current directory
cd %basedirname%%Currentdir%
IF EXIST "*.dsx" GOTO dsimpcmp
ECHO Great! You don't have any files to process.
cd %basedirname%
GOTO :EOF
:dsimpcmp
SET DParams= /D=%HostName% /H=%ServerName% /U=%userid% /P=%password% %project%
for %%F in (%basedirname%%Currentdir%*.dsx) do (
%DSImportCMD% %DParams% %%F >> %LogFileName%
)
cd %basedirname%
GOTO :EOF


Thanks,
Raju

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#7 Post by Squashman » 26 Jun 2013 17:38

As I said in your previous thread:

This is redundant

Code: Select all

for /F %%i in ("%~f0") do set filename=%%~ni

You can just use %~n0

This is also redundant.

Code: Select all

for %%F in ("%~f0") do set dirname=%%~dpF
SET basedirname=%dirname%

You can just use %~dp0

Your Echo statement does not have the correct explanation.

Code: Select all

IF NOT "%6"=="" (
    echo No more than four arguments, please check the arguments >> %LogFileName%
    goto :EOF
)

somu_june
Posts: 30
Joined: 19 Jun 2013 20:26

Re: for loop to trigger commands for each .dsx file

#8 Post by somu_june » 26 Jun 2013 17:58

Hi Squashman,

Thanks for correcting my mistakes. I corrected my code according to your feedback. I also added error handling after the for loop to exit the script if there are any errors, but I'm getting below error

H:\Data\Dir\Datastage>echo off
The syntax of the command is incorrect.

Code: Select all

:: ====================Written by Somaraju Buddharaju================================================================
:: ===========This script will loop through the .dsx files under Current directory and ======================
:: ========== imports the Datastage jobs and compiles the jobs if compile option is passed====================
:: ========== Script expects 5 input parameters 1.HostName like "INFETLD01, 2.userid : Datastage userid=======
::=========== 3.password: Datastage password, 4.project : Datastage project name like "CPT_DEV" ==============
::=========== 5. dscmp : Datastage compile option like "C" for compile and "N" for Not compile ===============
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
set dscmp=%5

REM =====Below %~f0  will provide obsolute path with filename
for /F %%i in ("%~f0") do set filename=%~n0
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 basedirname=%~dp0
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 "%6"=="" (
    echo No more than five arguments, please check the arguments >> %LogFileName%
    goto :EOF
)
if  "%5"=="" (
    echo please check the arguments, script expects 5 arguments >> %LogFileName%
   goto :EOF
)
:: Below exist command checks if .dsx file exists in the Current directory
cd %basedirname%%Currentdir%
IF EXIST "*.dsx" GOTO dsimpcmp
ECHO Great! You don't have any files to process.
cd %basedirname%
GOTO :EOF
:dsimpcmp
SET DParams= /D=%HostName% /H=%ServerName% /U=%userid% /P=%password% %project%
for %%F in (%basedirname%%Currentdir%*.dsx) do (
%DSImportCMD% %DParams% %%F >> %LogFileName%
)
IF %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER
cd %basedirname%
IF %dscmp%=="C"
type %basedirname%%Currentdir%*.dsx | repl "^(BEGIN DSJOB)\r?\n" "$1" m | findstr /brc:"BEGIN DSJOB *Identifier " | repl ".*\x22(.*)\x22.*" $1 > %basedirname%%Currentdir%%filename%_dsjoblist.txt
GOTO :EOF
:ERROR_HANDLER
echo -------------Error occured in importing or compiling please check log for details -------
exit 1




This is my first batch script and I really enjoying it with your help and support.

Thanks,
Raju.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#9 Post by Squashman » 26 Jun 2013 18:13

I can't run your script. So turn ECHO ON at the top of your script and run it. Then you can see what command it is executing when it gives you that error. You are your own best guide to troubleshooting errors. Always turn ECHO ON when you are getting errors to see what command it is executing when the error occurs.

My best guess is this extra code you added to the end of your script which I assume Dave or Foxidrive wrote for you. They will need to troubleshoot that for you. Something doesn't look right with it. Not sure if your code is actually like that in your script or if the FORUM is wrapping it.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#10 Post by Squashman » 26 Jun 2013 18:18

NO! This is not correct.

Code: Select all

for /F %%i in ("%~f0") do set filename=%~n0
for %%F in ("%~f0") do set basedirname=%~dp0

Just create a simple batch file and put these lines into it and then maybe you will understand.

Code: Select all

@echo off
echo Batch file name is: %~n0
echo Path to batch file is: %~dp0
pause

somu_june
Posts: 30
Joined: 19 Jun 2013 20:26

Re: for loop to trigger commands for each .dsx file

#11 Post by somu_june » 26 Jun 2013 18:28

Thank you,

I turned on echo on. This is what I see and it is not showing where the error is

H:\Data\Dir\Datastage\Current>("C:\IBM\InformationServer\Clients\Classic\dscmdim
port.exe" /D=INFETLD01:9080 /H=INFETLD01 /U=o99in44 /P=Snail123 CPT_DEV H:\Dat
a\Dir\Datastage\Current\PHP_Jobs.dsx 1>>H:\Data\Dir\Datastage\Result\test_20130
626_20_17_32.log )

H:\Data\Dir\Datastage\Current>("C:\IBM\InformationServer\Clients\Classic\dscmdim
port.exe" /D=INFETLD01:9080 /H=INFETLD01 /U=o99in44 /P=Snail123 CPT_DEV H:\Dat
a\Dir\Datastage\Current\ECI_Jobs.dsx 1>>H:\Data\Dir\Datastage\Result\test_20130
626_20_17_32.log )

H:\Data\Dir\Datastage\Current>IF 0 NEQ 0 GOTO ERROR_HANDLER

H:\Data\Dir\Datastage\Current>cd H:\Data\Dir\Datastage\
The syntax of the command is incorrect.

H:\Data\Dir\Datastage>IF C=="C"



Thanks,
Raju

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#12 Post by Squashman » 26 Jun 2013 19:46

Well for starters: C will never equal "C"
If you are going to use QUOTES on one side of your comparison you need to use them on the other side. Both sides should have them.

But that is the command that is giving you the syntax error because you have NO command to execute after it.

Try this at the command prompt

Code: Select all

C:\Users\Squash>IF "C"=="C"
The syntax of the command is incorrect.

C:\Users\Squash>IF "C"=="C" echo equal
equal


I am assuming you did not copy and paste some code that someone else gave you correctly. What thread did you get it from?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#13 Post by Squashman » 26 Jun 2013 19:49

I would assume you actually wanted to do this. This should be all on one line but the FORUM is wrapping it.

Code: Select all

IF %dscmp%=="C" type %basedirname%%Currentdir%*.dsx | repl "^(BEGIN DSJOB)\r?\n" "$1" m | findstr /brc:"BEGIN DSJOB *Identifier " | repl ".*\x22(.*)\x22.*" $1 >%basedirname%%Currentdir%%filename%_dsjoblist.txt

somu_june
Posts: 30
Joined: 19 Jun 2013 20:26

Re: for loop to trigger commands for each .dsx file

#14 Post by somu_june » 26 Jun 2013 19:54

Hi,

I changed the code to see exactly where the error is occuring. What I see is I'm getting messages saying string is too long

H:\Data\Dir\Datastage>IF C == C GOTO dscompile

H:\Data\Dir\Datastage>type H:\Data\Dir\Datastage\Current\*.dsx | repl "^(BEGIN
DSJOB)\r?\n" "$1" m | findstr /brc:"BEGIN DSJOB *Identifier " | repl ".*\x2
2(.*)\x22.*" $1 1>H:\Data\Dir\Datastage\Current\test_dsjoblist.txt

H:\Data\Dir\Datastage\Current\PHP_Jobs.dsx



H:\Data\Dir\Datastage\Current\ECI_Jobs.dsx


FINDSTR: Line 30475 is too long.
FINDSTR: Line 30475 is too long.
FINDSTR: Line 30475 is too long.
FINDSTR: Line 30475 is too long.
FINDSTR: Line 30475 is too long.
FINDSTR: Line 30475 is too long.
FINDSTR: Line 30475 is too long.
FINDSTR: Line 54798 is too long.
FINDSTR: Line 58062 is too long.
FINDSTR: Line 74838 is too long.

H:\Data\Dir\Datastage>IF 0 NEQ 0 GOTO ERROR_HANDLER

H:\Data\Dir\Datastage>GOTO :EOF

Code: Select all

:: ====================Written by Somaraju Buddharaju================================================================
:: ===========This script will loop through the .dsx files under Current directory and ======================
:: ========== imports the Datastage jobs and compiles the jobs if compile option is passed====================
:: ========== Script expects 5 input parameters 1.HostName like "INFETLD01, 2.userid : Datastage userid=======
::=========== 3.password: Datastage password, 4.project : Datastage project name like "CPT_DEV" ==============
::=========== 5. dscmp : Datastage compile option like "C" for compile and "N" for Not compile ===============
echo on
:: Setting the Datastage commands
SET DSImportCMD="C:\IBM\InformationServer\Clients\Classic\dscmdimport.exe"
SET DSCompileCMD="C:\IBM\InformationServer\Clients\Classic\dscc.exe"
Set HostName=%1:9080
Set ServerName=%1
set userid=%2
set password=%3
set project=%4
set dscmp=%5

REM =====Below %~f0  will provide obsolute path with filename
for /F %%i in ("%~f0") do set filename=%~n0
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 basedirname=%~dp0
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 "%6"=="" (
    echo No more than five arguments, please check the arguments >> %LogFileName%
    goto :EOF
)
if  "%5"=="" (
    echo please check the arguments, script expects 5 arguments >> %LogFileName%
   goto :EOF
)
:: Below exist command checks if .dsx file exists in the Current directory
cd %basedirname%%Currentdir%
IF EXIST "*.dsx" GOTO dsimport
ECHO Great! You don't have any files to process.
cd %basedirname%
GOTO :EOF
:dsimport
SET DParams= /D=%HostName% /H=%ServerName% /U=%userid% /P=%password% %project%
for %%F in (%basedirname%%Currentdir%*.dsx) do (
%DSImportCMD% %DParams% %%F >> %LogFileName%
)
IF %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER
cd %basedirname%
IF %dscmp%==C GOTO dscompile
GOTO :EOF
:dscompile
type %basedirname%%Currentdir%*.dsx | repl "^(BEGIN DSJOB)\r?\n" "$1" m | findstr /brc:"BEGIN DSJOB *Identifier " | repl ".*\x22(.*)\x22.*" $1 > %basedirname%%Currentdir%%filename%_dsjoblist.txt
IF %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER
GOTO :EOF
:ERROR_HANDLER
echo -------------Error occured in importing or compiling please check log for details -------
exit 1

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: for loop to trigger commands for each .dsx file

#15 Post by Squashman » 26 Jun 2013 19:58

Dave will have to help you with that. I have never used his REPL code so I haven't learned how it all works.

Post Reply