Some code to help compare jobs

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Some code to help compare jobs

Post by asorrell »

Command line comparison of a job in two different projects, placing the output in an html file: (Note: Windows!)

diffapicmdline.exe /lhscd "/d="HOSTNAME:PORT" /h="ENGINE" /u="USERID" /p="PASSWORD" "PROJECT" "JOBNAME"" /rhscd "/d="HOSTNAME:PORT" /h="ENGINE" /u="USERID" /p="PASSWORD" "PROJECT" "JOBNAME"" /t Job /ot html /ol "C:\OUTPUT.html"

Replace the upper case commands with appropriate system settings, etc. for your system.
---------------------------------
Automated Job Comparison Between Two Projects

To overcome time-consuming manual comparisons, this script will automatically compare numerous jobs and place output in a log and html file. The log file contains the comparison of each job and the html file contains the details of the differences between jobs.

Utility Name: DS_Job_Comparator_spec.bat

This utility uses C:\Program Files\IBM\InformationServer\Clients\Classic\diffapicmdline.exe to get the reports generated.

Preparation:

Place the list of jobs to be compared in a txt file to be consumed by the batch job

Execution:

Trigger the utility from the command prompt (from the location where its placed) and enter the details below as requested by the utility:
1. <SOURCE HOSTNAME:PORT>
2.<SOURCE LOGIN ID>
3.<SOURCE PASSWORD>
4.<SOURCE ENGINE>
5.<SOURCE PROJECT>
6.<TARGET HOSTNAME:PORT>
7.<TARGET LOGIN ID>
8.<TARGET PASSWORD>
9.<TARGET ENGINE>
10.<TARGET PROJECT>
11.<OUTPUT FOLDER>
12.<PATHNAME TO JOBLIST>

---------------------------------------------------------------------------

Code: Select all

SETLOCAL ENABLEDELAYEDEXPANSION
@ECHO OFF
::=================================================================================
::Script Name : DS_Automated_Project_Comparison.bat
::Script Purpose: This utility compares DataStage jobs between two different projects.
::Script Parameters: 1.<DS SRC DOMAIN> 2.<DS SRC LOGIN ID> 3.<DS SRC LOGIN PSWD> 4.<DS SRC SERVER NAME> 5.<DS SRC PROJECT> 6.<DS TARGET DOMAIN> 7.<DS TARGET LOGIN ID> 8.<DS Target LOGIN PSWD> 9.<DS target SERVER NAME> 10.<DS target PROJECT> 11.<target Folder> 12.<Parameter file>
::Script execution prerequisite : Keep the parameter file with the list of jobs
::Version#    Description               
::   1        Initial Version
::=================================================================================
SET /p DSTG_DOMAIN="Enter Source DataStage domain with port:(server.domain.com:port): "
SET /p LOGIN_USER="Enter Source DataStage user id:"
SET /p LOGIN_PSSWD="Enter Source DataStage password:"
SET /p DSTG_SERVER="Enter Source DataStage Server(sample: engine.domain.com):"
SET /p DSTG_PROJECT="Enter Source DataStage Project Space:"
SET /p DSTG_TRG_DOMAIN="Enter Target DataStage domain with port:(server.domain.com:port) : "
SET /p LOGIN_TRG_USER="Enter Target DataStage user id :"
SET /p LOGIN_TRG_PSSWD="Enter Target DataStage password :"
SET /p DSTG_TRG_SERVER="Enter Target DataStage Server(sample: engine.domain.com) :"
SET /p DSTG_TRG_PROJECT="Enter Target DataStage Project Space :"
SET /p JOB_LIST_PARAMFILE="Enter the Job list file :"
SET /p TGT_FOLDER="Enter the processing folder :"
SET JOB_LIST_PARAMFILE=%TGT_FOLDER%%JOB_LIST_PARAMFILE%
SET DS_UTIL_PATH="C:\IBM\InformationServer\Clients\Classic\"
SET V_TIME=%time::=%
SET V_TIME=%V_TIME:.=%
FOR /f "tokens=1-4 delims=/.- " %%A in ('date /t') do ( SET CurrentDate=%%B%%C%%D )
SET CurrentDate=%CurrentDate: =%
SET LOGFILE="%TGT_FOLDER%"Jobs_Comparator_Log_file_%CurrentDate%.txt
SET FLD_JOBLIST=%TGT_FOLDER%Folder_Joblist_%CurrentDate%.txt
SET STAT_FILE="%TGT_FOLDER%"Jobs_Comparator_Failedstatus_%CurrentDate%.txt
SET P_CNT=0
DEL %STAT_FILE% %LOGFILE%
TYPE %JOB_LIST_PARAMFILE% >> %FLD_JOBLIST%.txt
ECHO DataStage Jobs Comparator Report  >> %LOGFILE%
ECHO. >> %LOGFILE%
ECHO Started at: %CurrentDate1% %time% >> %LOGFILE%
ECHO. >> %LOGFILE%
SET /a sjcnt=0
ECHO Comparison of Jobs Started....
for /f "tokens=*" %%a in (%FLD_JOBLIST%.txt) do (
   echo "Comparing %%a"
   C:\"Program Files"\IBM\InformationServer\Clients\Classic\diffapicmdline.exe /lhscd "/d=%DSTG_DOMAIN% /h=%DSTG_SERVER% /u=%LOGIN_USER% /p=%LOGIN_PSSWD% %DSTG_PROJECT% %%a"  /rhscd "/d=%DSTG_TRG_DOMAIN% /h=%DSTG_TRG_SERVER% /u=%LOGIN_TRG_USER% /p=%LOGIN_TRG_PSSWD% %DSTG_TRG_PROJECT% %%a" /t Job /ot html /ol %TGT_FOLDER%%%a_%CurrentDate%.html
   IF !ErrorLevel! == 2 (
      ECHO %%a Job Not Found >> %STAT_FILE%
      ECHO %%a - Comparison Failed , Job Not found >> %LOGFILE%
      ) else (                                    
      type %TGT_FOLDER%%%a_%CurrentDate%.html | tail -3 | head -1 > %TGT_FOLDER%%%a_%CurrentDate%.dat
      for /f "tokens=*" %%K in (%TGT_FOLDER%%%a_%CurrentDate%.dat) do (
          set line=%%K
          set chars=!line:~0,200!
          echo !chars!
          echo !chars! > %TGT_FOLDER%%%a_%CurrentDate%.txt
          )
     FINDSTR ">No changes found" %TGT_FOLDER%%%a_%CurrentDate%.txt
     echo !Errorlevel!
     IF !Errorlevel! == 0 (
        ECHO %%a - Comparison is successful >> %LOGFILE%
        ECHO %TGT_FOLDER%%%a_%CurrentDate%.html - removed >> %LOGFILE%
        del %TGT_FOLDER%%%a_%CurrentDate%.html
        ) else (
        ECHO %%a Failed >> %STAT_FILE%
        ECHO %%a - Comparison Failed >> %LOGFILE%
        ECHO Refer to %TGT_FOLDER%%%a_%CurrentDate%.html >> %LOGFILE%
        )
     DEL %TGT_FOLDER%%%a_%CurrentDate%.dat                 
     DEL %TGT_FOLDER%%%a_%CurrentDate%.txt
     )
  set /a sjcnt=sjcnt+1
  )
del %FLD_JOBLIST%.txt
Echo Finished at: %CurrentDate1% %time% >> %LOGFILE%
ECHO. >> %LOGFILE%
ECHO %sjcnt% items compared successfully >> %LOGFILE%
ECHO 0 items failed export >> %LOGFILE%
ECHO. >> %LOGFILE%
Echo =============================== >> %LOGFILE%
ECHO Comparison Of Jobs completed.
ECHO Check the below log for more details:
ECHO %LOGFILE%
GOTO EOF

:EOF
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
Post Reply