Converting a DOS script to a AIX ksh script

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
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Converting a DOS script to a AIX ksh script

Post by I_Server_Whale »

Hi All,
I have a requirement where I need to convert the existing DOS (.bat) scripts to korn shell scripts. I'm posting this question since I'm a novice to shell scripting and gurus here are very knowledgeable on the subject, although this is not a pure DS question.

The below is an example of an existing DOS script:

Code: Select all

@ECHO OFF
REM Batch File [CRMCARS_VDS.bat] 
REM This file executes the CRM CARS Vality job first. 
REM If completely successful, it executes the CRM CARS DataStage (Ardent) job next (see :end).
REM Changed 01/28/04 to accept longer AMPROD file layout for new states

echo ******************************************************      > E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
echo Starting VALITY jobs...                                    >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
date /T                                                         >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
time /T                                                         >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
type E:\Ascential\CRM\CRMCARS\Data\CARSDATE                  >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
set clean=Y
del /Q E:\Ascential\CRM\CRMCARS\Scripts\*.end

PATH=.;E:\Ascent~1\INTEGR~1;E:\Ascent~1\INTEGR~1\userto~1\bin;%PATH%

cd E:\Ascent~1\CRM\CRMCARS\ScriptX
E:

:doPROD
set CURRSTEP=PROD10
bash PROD10.scr -ipe.env  PROD10.env -ipe.env ../ipe.env.sh >> ..\Logs\CRMCARSP.LOG
findstr "Done"  E:\Ascential\CRM\CRMCARS\Scripts\PROD10.end 
if errorlevel 1 goto abortP 
echo --%CURRSTEP% successful.                                   >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log

set CURRSTEP=PRDST20
bash PRDST20.scr -ipe.env  PRDST20.env -ipe.env ../ipe.env.sh >> ..\Logs\CRMCARSP.LOG
findstr "Done"  E:\Ascential\CRM\CRMCARS\Scripts\PRDST20.end 
if errorlevel 1 goto abortP 
echo --%CURRSTEP% successful.                                   >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log

set CURRSTEP=PROD31
bash PROD31.scr -ipe.env   PROD31.env -ipe.env ../ipe.env.sh  >> ..\Logs\CRMCARSP.LOG
findstr "Done"  E:\Ascential\CRM\CRMCARS\Scripts\PROD31.end 
if errorlevel 1 goto abortP 
echo --%CURRSTEP% successful.                                   >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log

goto doDRIV

:abortP
echo Error in %CURRSTEP%. Skipping to DRIVER                    >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
set clean=N

:doDRIV
set CURRSTEP=DRV40
bash DRV40.scr -ipe.env   DRV40.env -ipe.env ../ipe.env.sh  >> ..\Logs\CRMCARSP.LOG
findstr "Done"  E:\Ascential\CRM\CRMCARS\Scripts\DRV40.end 
if errorlevel 1 goto abortD
echo --%CURRSTEP% successful.                                   >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log

set CURRSTEP=LOAD50
bash LOAD50.scr -ipe.env   LOAD50.env -ipe.env ../ipe.env.sh  >> ..\Logs\CRMCARSP.LOG
findstr "Done"  E:\Ascential\CRM\CRMCARS\Scripts\LOAD50.end 
if errorlevel 1 goto abortD
echo --%CURRSTEP% successful.                                   >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log

goto end

:abortD
echo Error in %CURRSTEP%. Skipping to END                     >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
set clean=N

:end
if %clean%==N goto xend
echo All VALITY steps completed SUCCESSFULLY.                   >> E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log
copy E:\Ascential\CRM\CRMCARS\Logs\CRMCARS_VDS.log  E:\Ascential\CRM\CRMCARS\Data\ValCRMC.AOK
copy E:\Ascential\CRM\CRMCARS\Data\CARSDATE         E:\Ascential\CRM\CRMCARS\Temp\CARSDATE

REM  *** This section starts Datastage Job.  Done here to simplify scheduling.
echo *******************************>> E:\Ardent\DataStage\Projects\CRMProd\Logs\CRMCARS_DS.log
echo CARSDATE =                     >> E:\Ardent\DataStage\Projects\CRMProd\Logs\CRMCARS_DS.log
type e:\ASCENTIAL\CRM\CRMCARS\Data\carsdate >> E:\Ardent\DataStage\Projects\CRMProd\Logs\CRMCARS_DS.log
echo Starting CRM CARS jobs...      >> E:\Ardent\DataStage\Projects\CRMProd\Logs\CRMCARS_DS.log
date /T                             >> E:\Ardent\DataStage\Projects\CRMProd\Logs\CRMCARS_DS.log
time /T                             >> E:\Ardent\DataStage\Projects\CRMProd\Logs\CRMCARS_DS.log

CD E:\Ardent\DataStage\Projects\CRMProd\Scripts

DSJOB -file E:\Ardent\Logon\PROD\LOGON.INI HQS364 -run -jobstatus  -param RunType=RUN -param ParameterFile=e:\Ardent\DataStage\Projects\CRMProd\Parameters\Parameters.ini -param ProjectSuffix=CRMC -param ClearWorkArea=N -param OverRide=Y CRM_PROD Batch::CRMCMasterControl

SET ERRORLEVEL=0
IF NOT EXIST e:\Ardent\DataStage\Projects\CRMProd\Logs\CRMC_Completed SET ERRORLEVEL=1
IF NOT EXIST E:\Ardent\DataStage\Projects\CRMProd\logs\CRMC_Completed ECHO **** CRM CARS FAILED ---------->> E:\Ardent\DataStage\Projects\CRMProd\Logs\CRMCARS_DS.log
IF EXIST E:\Ardent\Datastage\Projects\CRMProd\logs\CRMC_Completed     ECHO **** CRM CARS COMPLETED ------->> E:\Ardent\Datastage\Projects\CRMProd\Logs\CRMCARS_DS.log
IF NOT EXIST E:\Ardent\DataStage\Projects\CRMProd\logs\CRMC_Completed ECHO **** CRM CARS FAILED ---------->> E:\ASCENTIAL\CRM\CRMCARS\Logs\CRMCARS_VDS.log
IF EXIST E:\Ardent\Datastage\Projects\CRMProd\logs\CRMC_Completed     ECHO **** CRM CARS COMPLETED ------->> E:\ASCENTIAL\CRM\CRMCARS\Logs\CRMCARS_VDS.log

:xend
time /T                                                         >> E:\ASCENTIAL\CRM\CRMCARS\Logs\CRMCARS_VDS.log
echo --End.                                                     >> E:\ASCENTIAL\CRM\CRMCARS\Logs\CRMCARS_VDS.log
echo ******************************************************     >> E:\ASCENTIAL\CRM\CRMCARS\Logs\CRMCARS_VDS.log
type E:\ASCENTIAL\CRM\CRMCARS\Logs\CRMCARS_VDS.log           >> E:\ASCENTIAL\CRM\CRMCARS\Logs\CRMCHist.log

REM  **********************************************************************************************************
REM  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
if %clean%==N echo !!!!!! Vality step FAILED !!!!!! 
if %clean%==N DELETE GoodJob.txt
IF NOT EXIST e:\Ardent\DataStage\Projects\CRMProd\Logs\CRMC_Completed echo !!!!!! DataStage Job FAILED !!!!!! 
IF NOT EXIST e:\Ardent\DataStage\Projects\CRMProd\Logs\CRMC_Completed DELETE GoodJob.txt
REM  **********************************************************************************************************
REM End Batch File [CRMCARS_VDS.bat]
And after I spent too many hours, I arrived at the following converted ksh:

Code: Select all


#!/bin/ksh
set +v
# Batch File [CRMCARS_VDS.ksh] 
# This file executes the CRM CARS Vality job first. 
# If completely successful, it executes the CRM CARS DataStage (Ardent) job next (see :end).
# Changed 01/28/04 to accept longer AMPROD file layout for new states

echo ************************************************* > /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
echo Starting VALITY jobs...                          >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
date '%a  %m/%d/%y  %H:%M:%S'                         >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
cat /Ascential/CRM/CRMCARS/Data/CARSDATE              >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
export clean=Y
rm /Ascential/CRM/CRMCARS/Scripts/*.end

PATH=.;/Ascent~1/INTEGR~1;/Ascent~1/INTEGR~1/userto~1/bin;$PATH
DSHOME=/datastage/Ascential/DataStage/DSEngine
FILE1=/Ardent/DataStage/Projects/CRMProd/Logs/CRMC_Completed

cd /Ascent~1/CRM/CRMCARS/ScriptX
E:

# doPROD
export CURRSTEP=PROD10
PROD10.scr -ipe.env  PROD10.env -ipe.env ../ipe.env.sh >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/PROD10.end 
if $?=1
      then
         echo Error in $CURRSTEP. Skipping to DRIVER   >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         export clean=N
         export CURRSTEP=DRV40
         DRV40.scr -ipe.env   DRV40.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
         grep "Done"  /Ascential/CRM/CRMCARS/Scripts/DRV40.end 
         if $?=1
               then
                  echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  export clean=N
                  date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
                  #  **********************************************************************************************************
                  #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
                  if $clean=N
                             then
                                echo !!!!!! Vality step FAILED !!!!!! 
                                rm GoodJob.txt
                  fi
                  if [! -e $FILE1 ]
                                  then
                                     echo !!!!!! DataStage Job FAILED !!!!!! 
                                     rm GoodJob.txt
                  fi
                  exit 1
               else
                  echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         fi
         export CURRSTEP=LOAD50
         LOAD50.scr -ipe.env   LOAD50.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
         grep "Done"  /Ascential/CRM/CRMCARS/Scripts/LOAD50.end 
         if $?=1
               then
                  echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  export clean=N
                  date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
                  #  **********************************************************************************************************
                  #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
                  if $clean=N
                             then
                                echo !!!!!! Vality step FAILED !!!!!! 
                                rm GoodJob.txt
                  fi
                  if [! -e $FILE1 ]
                                  then
                                     echo !!!!!! DataStage Job FAILED !!!!!! 
                                     rm GoodJob.txt
                  fi
                  exit 1
               else
                  echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
      else
         echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
fi

export CURRSTEP=PRDST20
PRDST20.scr -ipe.env  PRDST20.env -ipe.env ../ipe.env.sh >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/PRDST20.end 
if $?=1
      then
         echo Error in $CURRSTEP. Skipping to DRIVER   >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         export clean=N
         export CURRSTEP=DRV40
         DRV40.scr -ipe.env   DRV40.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
         grep "Done"  /Ascential/CRM/CRMCARS/Scripts/DRV40.end 
         if $?=1
               then
                  echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  export clean=N
                  date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
                  #  **********************************************************************************************************
                  #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
                  if $clean=N
                             then
                                echo !!!!!! Vality step FAILED !!!!!! 
                                rm GoodJob.txt
                  fi
                  if [! -e $FILE1 ]
                                  then
                                     echo !!!!!! DataStage Job FAILED !!!!!! 
                                     rm GoodJob.txt
                  fi
                  exit 1
               else
                  echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         fi
         export CURRSTEP=LOAD50
         LOAD50.scr -ipe.env   LOAD50.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
         grep "Done"  /Ascential/CRM/CRMCARS/Scripts/LOAD50.end 
         if $?=1
               then
                  echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  export clean=N
                  date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
                  #  **********************************************************************************************************
                  #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
                  if $clean=N
                             then
                                echo !!!!!! Vality step FAILED !!!!!! 
                                rm GoodJob.txt
                  fi
                  if [! -e $FILE1 ]
                                  then
                                     echo !!!!!! DataStage Job FAILED !!!!!! 
                                     rm GoodJob.txt
                  fi
                  exit 1
               else
                  echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
      else
         echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
fi

export CURRSTEP=PROD31
PROD31.scr -ipe.env   PROD31.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/PROD31.end 
if $?=1
      then
         echo Error in $CURRSTEP. Skipping to DRIVER   >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         export clean=N
         export CURRSTEP=DRV40
         DRV40.scr -ipe.env   DRV40.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
         grep "Done"  /Ascential/CRM/CRMCARS/Scripts/DRV40.end 
         if $?=1
               then
                  echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  export clean=N
                  date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
                  #  **********************************************************************************************************
                  #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
                  if $clean=N
                             then
                                echo !!!!!! Vality step FAILED !!!!!! 
                                rm GoodJob.txt
                  fi
                  if [! -e $FILE1 ]
                                  then
                                     echo !!!!!! DataStage Job FAILED !!!!!! 
                                     rm GoodJob.txt
                  fi
                  exit 1
               else
                  echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         fi
         export CURRSTEP=LOAD50
         LOAD50.scr -ipe.env   LOAD50.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
         grep "Done"  /Ascential/CRM/CRMCARS/Scripts/LOAD50.end 
         if $?=1
               then
                  echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  export clean=N
                  date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
                  cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
                  #  **********************************************************************************************************
                  #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
                  if $clean=N
                             then
                                echo !!!!!! Vality step FAILED !!!!!! 
                                rm GoodJob.txt
                  fi
                  if [! -e $FILE1 ]
                                  then
                                     echo !!!!!! DataStage Job FAILED !!!!!! 
                                     rm GoodJob.txt
                  fi
                  exit 1
               else
                  echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
      else
         echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
fi

export CURRSTEP=DRV40
DRV40.scr -ipe.env   DRV40.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/DRV40.end 
if $?=1
      then
         echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         export clean=N
         date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
         #  **********************************************************************************************************
         #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
         if $clean=N
                   then
                      echo !!!!!! Vality step FAILED !!!!!! 
                      rm GoodJob.txt
         fi
         if [! -e $FILE1 ]
                        then
                           echo !!!!!! DataStage Job FAILED !!!!!! 
                           rm GoodJob.txt
         fi
         exit 1
      else
         echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
fi

export CURRSTEP=LOAD50
LOAD50.scr -ipe.env   LOAD50.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/LOAD50.end 
if $?=1
      then
         echo Error in $CURRSTEP. Skipping to END      >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         export clean=N
         date '%H:%M:%S'                               >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         echo --End.                                   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         echo ******************************************************  >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
         cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log
         #  **********************************************************************************************************
         #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
         if $clean=N
                   then
                      echo !!!!!! Vality step FAILED !!!!!! 
                      rm GoodJob.txt
         fi
         if [! -e $FILE1 ]
                        then
                           echo !!!!!! DataStage Job FAILED !!!!!! 
                           rm GoodJob.txt
         fi
         exit 1
      else
         echo --$CURRSTEP successful.                  >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
fi

# end
echo All VALITY steps completed SUCCESSFULLY.          >> /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log
cp /Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log /Ascential/CRM/CRMCARS/Data/ValCRMC.AOK
cp /Ascential/CRM/CRMCARS/Data/CARSDATE /Ascential/CRM/CRMCARS/Temp/CARSDATE

#  *** This section starts Datastage Job.  Done here to simplify scheduling.
echo *******************************     >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
echo CARSDATE =                          >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
cat /ASCENTIAL/CRM/CRMCARS/Data/carsdate >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
echo Starting CRM CARS jobs...           >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
date '%a  %m/%d/%y  %H:%M:%S'            >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log

CD /Ardent/DataStage/Projects/CRMProd/Scripts

$DSHOME/bin/dsjob -file /Ardent/Logon/PROD/LOGON.INI HQS364 -run -jobstatus  -param RunType=RUN -param 

ParameterFile=/Ardent/DataStage/Projects/CRMProd/Parameters/Parameters.ini -param ProjectSuffix=CRMC -param ClearWorkArea=N -param 

OverRide=Y CRM_PROD Batch::CRMCMasterControl

export $?=0
if [! -e $FILE1 ]
               then
                  export $?=1
                  ECHO **** CRM CARS FAILED ---------->> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
                  ECHO **** CRM CARS FAILED ---------->> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
fi
if [ -e $FILE1 ]
               then
                  ECHO **** CRM CARS COMPLETED ------->> /Ardent/Datastage/Projects/CRMProd/Logs/CRMCARS_DS.log
                  ECHO **** CRM CARS COMPLETED ------->> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
fi

#xend
date '%H:%M:%S'                                 >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
echo --End.                                     >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
echo ****************************************   >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log
cat /ASCENTIAL/CRM/CRMCARS/Logs/CRMCARS_VDS.log >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log

#  **********************************************************************************************************
#  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
if $clean=N
          then
             echo !!!!!! Vality step FAILED !!!!!! 
             rm GoodJob.txt
fi
if [! -e $FILE1 ]
               then
                  echo !!!!!! DataStage Job FAILED !!!!!! 
                  rm GoodJob.txt
fi
#  **********************************************************************************************************
# End Batch File [CRMCARS_VDS.ksh]
exit 0
I would really appreciate if someone could evaluate the conversion and point out any flaws/mistakes or suggest better code.

Many Thanks in advance,
Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

To be really honest, the script is long and dont have the time to go through it, but a few pointers.
Create a variable that holds the path of your log files and then re-direct to the variable instead of the entire path. If your log file path changes, you will have to change it in one place, instead of 10 different places.

Create functions like the original bat script. This way it will be in seperate modules.

My 2 cents.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

DSguru2B wrote: To be really honest, the script is long and dont have the time to go through it, but a few pointers.
No problemo, but thanks for the pointers.
DSguru2B wrote: Create a variable that holds the path of your log files and then re-direct to the variable instead of the entire path. If your log file path changes, you will have to change it in one place, instead of 10 different places.
Good one, I will implement it immediately.
DSguru2B wrote: Create functions like the original bat script. This way it will be in seperate modules.
Didn't really understand this statement. If possible, can you please provide an example. That would be tremendously appreciated.

Many thanks again,
Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Create functions like your original bat script has (doPROD, doEND, doDRIV etc).
In a korn shell it would be something like

Code: Select all

-----
----
----
------
doPROD()
{
   -----
   -----
   -----
}

doDRIV()
{
   -----
   -----
   -----
}

########
#   MAIN   #
########
doPROD

doDRIV

other_functions

  
This way you can have error handling in each one of the functions seperately. Debugging can be easy. Plus the over all script will be readable. Documentation will be easy as it will describe each function seperately. Tomorrow if you want a new functionality, write another function and call it. If you dont want something, instead of deleting 10 lines, comment out the function call and those lines wont be executed.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Awesome!! DSguru2B. I have struggled for couple of hours and applied your suggestions and arrived at the following code using functions.

Code: Select all

#!/bin/ksh
set +v
# Batch File [CRMCARS_VDS.ksh] 
# This file executes the CRM CARS Vality job first. 
# If completely successful, it executes the CRM CARS DataStage (Ardent) job next (see :end).
# Changed 01/28/04 to accept longer AMPROD file layout for new states

PATH=.;/Ascent~1/INTEGR~1;/Ascent~1/INTEGR~1/userto~1/bin;$PATH
DSHOME=/datastage/Ascential/DataStage/DSEngine
FILE1=/Ardent/DataStage/Projects/CRMProd/Logs/CRMC_Completed
LOGFILE=/Ascential/CRM/CRMCARS/Logs/CRMCARS_VDS.log


echo ************************************************* > $LOGFILE
echo Starting VALITY jobs...                          >> $LOGFILE
date '%a  %m/%d/%y  %H:%M:%S'                         >> $LOGFILE
cat /Ascential/CRM/CRMCARS/Data/CARSDATE              >> $LOGFILE
export clean=Y
rm /Ascential/CRM/CRMCARS/Scripts/*.end

cd /Ascent~1/CRM/CRMCARS/ScriptX
E:

abortP () {
     echo Error in $CURRSTEP. Skipping to DRIVER   >> $LOGFILE
     export clean=N
     doDRIV
}

abortD () {
     echo Error in $CURRSTEP. Skipping to END      >> $LOGFILE
     export clean=N
}

doDRIV () {
     export CURRSTEP=DRV40
     DRV40.scr -ipe.env   DRV40.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
     grep "Done"  /Ascential/CRM/CRMCARS/Scripts/DRV40.end
     if $?=1
           then
               abortD
               end
           else
              echo --$CURRSTEP successful.         >> $LOGFILE
     fi

     export CURRSTEP=LOAD50
     LOAD50.scr -ipe.env   LOAD50.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
     grep "Done"  /Ascential/CRM/CRMCARS/Scripts/LOAD50.end 
     if $?=1
           then
              abortD
              end
           else
              echo --$CURRSTEP successful.         >> $LOGFILE
     fi

     end
     exit 0
}

end () {
  if $clean=N
            then
               xend
            else
               echo All VALITY steps completed SUCCESSFULLY.          >> $LOGFILE
               cp $LOGFILE /Ascential/CRM/CRMCARS/Data/ValCRMC.AOK
               cp /Ascential/CRM/CRMCARS/Data/CARSDATE /Ascential/CRM/CRMCARS/Temp/CARSDATE

               #  *** This section starts Datastage Job.  Done here to simplify scheduling.
               echo *******************************     >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
               echo CARSDATE =                          >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
               cat /ASCENTIAL/CRM/CRMCARS/Data/carsdate >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
               echo Starting CRM CARS jobs...           >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
               date '%a  %m/%d/%y  %H:%M:%S'            >> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log

               CD /Ardent/DataStage/Projects/CRMProd/Scripts

               $DSHOME/bin/dsjob -file /Ardent/Logon/PROD/LOGON.INI HQS364 -run -jobstatus  -param RunType=RUN -param 

ParameterFile=/Ardent/DataStage/Projects/CRMProd/Parameters/Parameters.ini -param ProjectSuffix=CRMC -param ClearWorkArea=N -

param OverRide=Y CRM_PROD Batch::CRMCMasterControl

               export $?=0
               if [! -e $FILE1 ]
                      then
                         export $?=1
                         ECHO **** CRM CARS FAILED ---------->> /Ardent/DataStage/Projects/CRMProd/Logs/CRMCARS_DS.log
                         ECHO **** CRM CARS FAILED ---------->> $LOGFILE
               fi
               if [ -e $FILE1 ]
                     then
                        ECHO **** CRM CARS COMPLETED ------->> /Ardent/Datastage/Projects/CRMProd/Logs/CRMCARS_DS.log
                        ECHO **** CRM CARS COMPLETED ------->> $LOGFILE
               fi
}

xend () {
   date '%H:%M:%S'                                 >> $LOGFILE
   echo --End.                                     >> $LOGFILE
   echo ****************************************   >> $LOGFILE
   cat $LOGFILE >> /ASCENTIAL/CRM/CRMCARS/Logs/CRMCHist.log

   #  **********************************************************************************************************
   #  *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
   if $clean=N
          then
             echo !!!!!! Vality step FAILED !!!!!! 
             rm GoodJob.txt
   fi
   if [! -e $FILE1 ]
               then
                  echo !!!!!! DataStage Job FAILED !!!!!! 
                  rm GoodJob.txt
   fi
   #  **********************************************************************************************************
}

######## MAIN ########
# **************************************************************************************************************
# doPROD
export CURRSTEP=PROD10
PROD10.scr -ipe.env  PROD10.env -ipe.env ../ipe.env.sh >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/PROD10.end 
if $?=1
      then
         abortP
      else
         echo --$CURRSTEP successful.                  >> $LOGFILE
fi

export CURRSTEP=PRDST20
PRDST20.scr -ipe.env  PRDST20.env -ipe.env ../ipe.env.sh >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/PRDST20.end 
if $?=1
      then
         abortP
      else
         echo --$CURRSTEP successful.                  >> $LOGFILE
fi

export CURRSTEP=PROD31
PROD31.scr -ipe.env   PROD31.env -ipe.env ../ipe.env.sh  >> ../Logs/CRMCARSP.LOG
grep "Done"  /Ascential/CRM/CRMCARS/Scripts/PROD31.end 
if $?=1
      then
         abortP
      else
         echo --$CURRSTEP successful.                  >> $LOGFILE
fi

doDRIV

end

xend
#  ************************************************************************************************************
# End Batch File [CRMCARS_VDS.ksh]
exit 0
I have created abortP(), abortD(), doDRIV(), end() and xend() functions.
Since, the conversion is being done remotely with no UNIX\LINUX system to test it. I'd really appreciate if you could give it a cursory glance and evaluate it. That will help me in gaining confidence to progress further.
Again, thanks a bunch !!!

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I_Server_Whale wrote:

# **********************************************************************************************************
# *** This section creates ABORT condition in Maestro when either Vality or DataStage failed . *************
if $clean=N
then
echo !!!!!! Vality step FAILED !!!!!!
rm GoodJob.txt
fi
if [! -e $FILE1 ]
then
echo !!!!!! DataStage Job FAILED !!!!!!
rm GoodJob.txt
fi
# **********************************************************************************************************
Where will GoodJob.txt sit? Its a better idea to fully qualify names of any files you read from or write to.

Get some arrangements done to test the script out. I have been scripting for some years now but every now and then leave out something. Testing is always good :wink:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

DSguru2B wrote: Where will GoodJob.txt sit? Its a better idea to fully qualify names of any files you read from or write to.

Get some arrangements done to test the script out. I have been scripting for some years now but every now and then leave out something. Testing is always good :wink:
Will work on that. Many thanks DSguru2B !! :)

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
Post Reply