@echo off
:: Required Components:
:: dsjob.exe (Windows Version)
:: -----------------------------------------------------------------
:: Command Line Parameters:
:: 1. Host
:: 2. User
:: 3. Password
:: 4. Project
:: -----------------------------------------------------------------
:: Ensure that everything that are set here are not permanent.
:: -----------------------------------------------------------------
SETLOCAL
:: -----------------------------------------------------------------
:: Test for command line parameters.
:: -----------------------------------------------------------------
IF "%1"=="" GOTO Syntax
IF "%2"=="" GOTO Syntax
IF "%3"=="" GOTO Syntax
IF "%4"=="" GOTO Syntax
:: -----------------------------------------------------------------
:: Set paramters.
:: -----------------------------------------------------------------
SET Host=%1
SET User=%2
SET Password=%3
SET Project=%4
:: -----------------------------------------------------------------
:: Hard-coded values. Dependent on each computer.
:: -----------------------------------------------------------------
SET Designer=C:\Progra~1\Ascential\DataStage\dsdesign.exe
SET DsJob=C:\Progra~1\Ascential\DataStage\dsjob.exe
SET JobList=DsJobReportList.txt
SET ProjectList=ProjectList.txt
SET DSLog=DsJobReportLog
SET BackupDir=c:\DataStage\KimD\Jobs\%Project%
:: -----------------------------------------------------------------
:: 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 delimeters so that current time can be broken down into components
:: then execute FOR loop to parse the DsxTime variable into Hr/Min/Sec/Hun.
:: -----------------------------------------------------------------
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
)
:: -----------------------------------------------------------------
:: If provided directory is missing an ending \, append it.
:: Validate %BackupDir%'s existance.
:: -----------------------------------------------------------------
if exist %BackupDir%\ set BackupDir=%BackupDir%\
if NOT exist %BackupDir% GOTO BadMain
:: -----------------------------------------------------------------
:: Set the log file name to improve readability of code.
SET LogFileName=%BackupDir%%DSLog%-%DsxDate%-%DsxHr%_%DsxMin%_%DsxSec%.log
:: -----------------------------------------------------------------
:: Announce to log of this program's run.
:: -----------------------------------------------------------------
ECHO. > %LogFileName%
ECHO DsJobReport ran on %DsxDate% %DsxHr%:%DsxMin%:%DsxSec% with the following parameters >> %LogFileName%
ECHO Host=%Host% >> %LogFileName%
ECHO User=%User% >> %LogFileName%
ECHO BackupDir=%BackupDir%%DsxDate%\ >> %LogFileName%
ECHO Designer=%Designer% >> %LogFileName%
ECHO DsJob=%DsJob% >> %LogFileName%
ECHO ProjectList=%ProjectList% >> %LogFileName%
ECHO JobList=%JobList% >> %LogFileName%
ECHO DSLog=%DSLog% >> %LogFileName%
ECHO. >> %LogFileName%
:: -----------------------------------------------------------------
:: Pull project information (and validate parameters).
:: -----------------------------------------------------------------
%DsJob% -server %Host% -user %User% -password %Password% -lprojects > %ProjectList%
IF NOT %ERRORLEVEL%==0 GOTO BadParam
:: -----------------------------------------------------------------
:: Pull job list
:: -----------------------------------------------------------------
%DsJob% -server %Host% -user %User% -password %Password% -ljobs %Project% > %JobList%
IF NOT %ERRORLEVEL%==0 GOTO BadParam
:: -----------------------------------------------------------------
:: Report valid projects to log.
:: -----------------------------------------------------------------
ECHO Jobs found on %Host%: >> %LogFileName%
type %JobList% >> %LogFileName%
:: -----------------------------------------------------------------
:: Create subdirectory within Backup Directory
:: Validate ability to create %BackupDir%%DsxDate%\.
:: -----------------------------------------------------------------
if exist %BackupDir%%DsxDate%\ GOTO DirCont
ECHO *** Creating: %BackupDir%%DsxDate%\
mkdir %BackupDir%%DsxDate%\
IF NOT %ERRORLEVEL%==0 GOTO BadDir
ECHO. >> %LogFileName%
ECHO *** Created: %BackupDir%%DsxDate%\ >> %LogFileName%
ECHO. >> %LogFileName%
:: -----------------------------------------------------------------
:DirCont
ECHO.
ECHO Saving Job Report on %Host% ...
ECHO.
:: -----------------------------------------------------------------
:: Begin Backup Loop
::
:: NOTE: %ERRORLEVEL% does not work for some reason.
:: -----------------------------------------------------------------
for /F "tokens=1" %%i in (%JobList%) do (
ECHO Saving Job Report on Job %%i
ECHO %Designer% /H=%Host% /U=%User% /P=%Password% %Project% %%i /R /RP=%BackupDir%%DsxDate% /RX >> %LogFileName%
%Designer% /H=%Host% /U=%User% /P=%Password% %Project% %%i /R /RP=%BackupDir%%DsxDate% /RX >> %LogFileName%
IF NOT %ERRORLEVEL%==0 GOTO ProjFail
ECHO. >> %LogFileName%
ECHO *** Completed Job Report for Job: %%i on Host: %Host% Project: %Project% >> %LogFileName%
ECHO to File: %BackupDir%%DsxDate%\%%i.html >> %LogFileName%
ECHO. >> %LogFileName%
)
:: -----------------------------------------------------------------
:: ECHO *** Export completed successfully for projects:
:: type %TempFile%
:: -----------------------------------------------------------------
GOTO EXITPT
:: -----------------------------------------------------------------
:: a job failed to be exported.
:: -----------------------------------------------------------------
:ProjFail
ECHO.
ECHO *** ERROR: Failed to Export Job: %%i on Host: %Host% on Project: %Project%
ECHO.
ECHO Please ensure that nobody else is accessing this server while you
ECHO are running this backup script.
ECHO.
ECHO. >> %LogFileName%
ECHO *** ERROR: Failed to Export Job: %%i on Host: %Host% on Project: %Project% >> %LogFileName%
ECHO. >> %LogFileName%
GOTO EXITPT
:: -----------------------------------------------------------------
:: Report that paramters are not valid on screen and log file.
:: Note: Password are not reported for better security.
:: -----------------------------------------------------------------
:BadParam
echo.
echo Invalid parameters - Unable to access Server.
echo.
echo. >> %LogFileName%
echo Invalid parameters - Unable to access Server. >> %LogFileName%
echo. >> %LogFileName%
GOTO Syntax
:: -----------------------------------------------------------------
:: Report that directory is non-existant.
:: -----------------------------------------------------------------
:BadMain
echo.
echo Bad/Non-existing directory: %BackupDir%
echo.
echo Please ensure that you have permission to access/create directories
echo and files. Also ensure that directory listed exists.
echo.
echo. >> %LogFileName%
echo Bad/Non-existing directory: %BackupDir% >> %LogFileName%
echo. >> %LogFileName%
GOTO EXITPT
:: -----------------------------------------------------------------
:: Report that program does not have privs to create directory.
:: -----------------------------------------------------------------
:BadDir
echo.
echo Unable to create subdirectory: %BackupDir%%DsxDate%\
echo.
echo Please ensure that you have permission to access/create directories
echo and files.
echo.
echo. >> %LogFileName%
echo Unable to create subdirectory: %BackupDir%%DsxDate%\ >> %LogFileName%
echo. >> %LogFileName%
GOTO EXITPT
:: -----------------------------------------------------------------
:: Report proper syntax usage.
:: -----------------------------------------------------------------
GOTO ENDPOINT
:: -----------------------------------------------------------------
:EXITPT
ECHO. >> %LogFileName%
:: -----------------------------------------------------------------
:ENDPOINT
ENDLOCAL
Tuesday, January 15, 2013
Datastage Job Report Script
by Unknown |
in Datastage
at 4:37 AM
Related Posts
-
What is ETL Mapping Document ?A Real Time Example
-
Netezza Performance Check Querys
-
Netezza Commands
-
Use of Default or Dummy row in dimension table
-
Netezza ISNUMERIC Data Check Logic
-
Datastage Error and reject record Handling simplified
-
Conformed Dimensions with example
-
Data Generation Using DataStage
-
Datastage Universe Quick Refrence
-
What exactly is Data Lineage? and Data Lineage tools
0 comments: