Translate to your Language

Disclaimer Statement

Total Pageviews

Track

Follow us on FaceBook

About

Powered by Blogger.

Blog Archive

Popular Posts

Thursday, September 23, 2010

DOS Batch Script to Export DataStage Jobs Automatically from a Project

by Unknown  |  in DataStage at  8:39 PM

Copy the following script into a text file and rename into ".bat" file

@echo off
:: -----------------------------------------------------------------
:: DataStageExportJobs.bat
:: -----------------------------------------------------------------
:: This batch script is used to Export all jobs from a Projects
:: This script must be run from a DataStage client machine and the parameters below should be given
:: -----------------------------------------------------------------
:: Host is server name
:: User is DataStage username
:: Password   is DataStage password
:: ImpLocation is the directory where the datastage dsx's are stored
:: -----------------------------------------------------------------
::    IF "%1"=="" GOTO MissingParameter
::    IF "%2"=="" GOTO MissingParameter
::    IF "%3"=="" GOTO MissingParameter
::    IF "%4"=="" GOTO MissingParameter
::    IF "%5"=="" GOTO MissingParameter
::------------------------------------------------------------------
SET Host=%1
SET Project=%2
SET User=%3
SET Password=%4
SET ExpLocation=%5
SET JobList=%ExpLocation%\JobList.txt

:: -----------------------------------------------------------------
:: Get the current Date
:: -----------------------------------------------------------------
    FOR /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do SET DsxDate=%%c%%a%%b
:: -----------------------------------------------------------------
:: Get the current Time
:: -----------------------------------------------------------------
    FOR /f "tokens=1* delims=:" %%a in ('ECHO.^|TIME^|FINDSTR "[0-9]"') do (SET DsxTime=%%b)
:: -----------------------------------------------------------------
    SET delim1=%DsxTime:~3,1%
    SET delim2=%DsxTime:~9,1%
    FOR /f "tokens=1-4 delims=%delim1%%delim2% " %%a in ('echo %DsxTime%') do (
        set DsxHr=%%a
        set DsxMin=%%b
        set DsxSec=%%c
        set DsxHun=%%d
    )
:: -----------------------------------------------------------------
:: Set the log file name
:: -----------------------------------------------------------------
    SET LogFileName=%ProjectDir%\DataStageImport_bat_%DsxDate%_%DsxHr%_%DsxMin%_%DsxSec%.log
:: -----------------------------------------------------------------
:: Main
:: -----------------------------------------------------------------
SET ArchiveDir=Archive_%DsxDate%_%DsxHr%_%DsxMin%_%DsxSec%
    cd %ExpLocation%
    mkdir %ArchiveDir%
    MOVE *.dsx %ArchiveDir%
    MOVE *.log %ArchiveDir%

:: -----------------------------------------------------------------
:: Create a log file name to output
:: -----------------------------------------------------------------
    ECHO. > %LogFileName%
    ECHO DataStage Export ran on %DsxDate% %DsxHr%:%DsxMin%:%DsxSec% with the following parameters >> %LogFileName%
    ECHO Host=%Host% >> %LogFileName%
    ECHO User=%user% >> %LogFileName%
    ECHO Project=%Project% >> %LogFileName%
    ECHO ExportDir=%ExpLocation% >> %LogFileName%
    ECHO JobList=%JobList% >> %LogFileName%
    ECHO. >> %LogFileName%
:: -----------------------------------------------------------------
:: Change the local directory to DataStage instalation Directory
:: This must be modified based on the DataStage Instalation Drive
:: -----------------------------------------------------------------
cd C:\Program Files\Ascential\DataStage7.5.2\
    for /F "tokens=1" %%i in (%JobList%) do (
        ECHO Exporting %%i to Project: %Project% on Host: %Host%
        echo dscmdexport /H=%Host% /U=%User% /P=%Password% %Project% %ExpLocation%\%%i >> %LogFileName%
        dscmdexport /H=%Host% /U=%User% /P=%Password% /NUA %Project% %ExpLocation%\%%i /V >> %ExpLocation%\%LogFileName%
IF NOT %ERRORLEVEL%==0 GOTO ERROR
        ECHO. >> %LogFileName%
        ECHO *** Completed Export of Project: %Project% on Host: %Host% >> %LogFileName%
        ECHO     from File: %ExpLocation%\%%i >> %LogFileName%
        ECHO. >> %LogFileName%
    )
:: -----------------------------------------------------------------
:: ERROR: Checking's
:: -----------------------------------------------------------------
::-------------------------------------------------------------------------------------------------
:MissingParameter
ECHO Missing Parameters
ECHO Please make sure you have enterd HostName,Project,UserName,Password and ImportLocation correctly
cd %ImpLocation%
rmdir %ExpLocation%\%ArchiveDir% /s/q
GOTO END
::------------------------------------------------------------------
:ExportFailed
    ECHO.
    ECHO *** ERROR:  Failed to Export Project: %Project% on Host: %Host%
    ECHO. >> %LogFileName%
    ECHO *** ERROR:  Failed to Export File: %ExpLocation%\%%i Project: %Project% on Host: %Host% >> %LogFileName%
    ECHO. >> %LogFileName%
rmdir %ExpLocation%\%ArchiveDir%
GOTO ERROR
:: -----------------------------------------------------------------
:ERROR
ECHO Export Failed,Please make sure all parameters are given and Files are in place
rmdir %ExpLocation%\%ArchiveDir%
GOTO END
::-----------------------------------------------------------------
:ENDS
   ECHO. >> %LogFileName%
   ECHO successfully Exported
:END

0 comments:

© Copyright © 2014Bigdata-dwbi. by