datastage指令碼排程
轉自:http://www.blogjava.net/xichengmylove/default.html?page=2
呼叫dsjob的shell script
#!/bin/ksh
#######
################################################################################
#######
####### FILE: MasterControl.ksh
#######
####### DESCRIPTION: Starts a DataStage MasterControl type job passing
####### all runtime parameter values
#######
#######
####### Date Version Developer Description
####### ---------- --------- -------------- ------------------------------------
####### 2002-05-15 1.0 Ken Bland Initial release
####### 2002-06-27 2.2 Ken Bland FileSetDate/ProcessDate modifications
####### 2002-07-10 2.2 Steve Boyce Added ProcessDate as 14th parameter
####### 2002-08-16 2.3 Steve Boyce Now calls stored procedure
####### GET_NEW_BATCH_NBR in datastage schema
####### instead of deriving it and inserting
####### here.
####### Uses comSQLPlus.ksh and comPLSQL.ksh
####### instead of SQLPlusStub.ksh.ksh
#######
PROG=`basename ${0}`
EXIT_STATUS=0
NOW=`date`
echo "${NOW} ${PROG} Initialization..."
echo
#######
####### CONFIGURATION ##########################################################
#######
if [ ${#} -ne 14 ]; then
echo "${NOW} ${PROG} : Invalid parameter list."
echo "${NOW} ${PROG} : The script needs 14 parameters:"
echo "${NOW} ${PROG} : JobName"
echo "${NOW} ${PROG} : ParameterFile"
echo "${NOW} ${PROG} : FileSetDate (YYYY-MM-DD)"
echo "${NOW} ${PROG} : BatchNumber"
echo "${NOW} ${PROG} : JobHierarchyFile"
echo "${NOW} ${PROG} : SourceSystemList"
echo "${NOW} ${PROG} : SubjectAreaList"
echo "${NOW} ${PROG} : ClearWorkArea"
echo "${NOW} ${PROG} : StartingMilestone"
echo "${NOW} ${PROG} : EndingMilestone"
echo "${NOW} ${PROG} : DebugMode"
echo "${NOW} ${PROG} : JobLinkStatisticChecksFile"
echo "${NOW} ${PROG} : ResurrectLogFile"
echo "${NOW} ${PROG} : ProcessDate (NULL|YYYY-MM-DD H24:MI:SS)"
exit 99
fi
JobName="${1}"
ParameterFile="${2}"
FileSetDate="${3}"
BatchNumber="${4}"
JobHierarchyFile="${5}"
SourceSystemList="${6}"
SubjectAreaList="${7}"
ClearWorkArea="${8}"
StartingMilestone="${9}"
EndingMilestone="${10}"
DebugMode="${11}"
JobLinkStatisticChecksFile="${12}"
ResurrectLogFile="${13}"
ProcessDate="${14}"
echo "${NOW} ${PROG} JobName ${JobName}"
echo "${NOW} ${PROG} ParameterFile ${ParameterFile}"
echo "${NOW} ${PROG} FileSetDate ${FileSetDate}"
echo "${NOW} ${PROG} BatchNumber ${BatchNumber}"
echo "${NOW} ${PROG} JobHierarchyFile ${JobHierarchyFile}"
echo "${NOW} ${PROG} SourceSystemList ${SourceSystemList}"
echo "${NOW} ${PROG} SubjectAreaList ${SubjectAreaList}"
echo "${NOW} ${PROG} ClearWorkArea ${ClearWorkArea}"
echo "${NOW} ${PROG} StartingMilestone ${StartingMilestone}"
echo "${NOW} ${PROG} EndingMilestone ${EndingMilestone}"
echo "${NOW} ${PROG} DebugMode ${DebugMode}"
echo "${NOW} ${PROG} JobLinkStatisticChecksFile ${JobLinkStatisticChecksFile}"
echo "${NOW} ${PROG} ResurrectLogFile ${ResurrectLogFile}"
echo "${NOW} ${PROG} ProcessDate ${ProcessDate}"
echo
# Below will look in the parameters.ini file to determine the directory path each.
UserID=`whoami`
BinFileDirectory=`cat /.dshome`/bin
LogFileDirectory=`grep -w LogFileDirectory ${ParameterFile}|cut -d "=" -f2`
TempFileDirectory=`grep -w TempFileDirectory ${ParameterFile}|cut -d "=" -f2`
CommonScriptFileDirectory=`grep -w CommonScriptFileDirectory ${ParameterFile}|cut -d "=" -f2`
CommonLogFileDirectory=`grep -w CommonLogFileDirectory ${ParameterFile}|cut -d "=" -f2`
LogFileName=${CommonLogFileDirectory}/${PROG}_${JobName}.log
TEMPBATCHNBRLOG=${TempFileDirectory}/${PROG}_${JobName}_start.log
DATASTAGEPROJECT=`grep -w DATASTAGEPROJECT ${ParameterFile}|cut -d "=" -f2`
DSSERVER=`grep -w DSSERVER ${ParameterFile}|cut -d "=" -f2`
DSUSERID=`grep -w DSUSERID ${ParameterFile}|cut -d "=" -f2`
DSPASSWORD=`grep -w DSPASSWORD ${ParameterFile}|cut -d "=" -f2`
NOW=`date`
echo "${NOW} ${PROG} UserID ${UserID}"
echo "${NOW} ${PROG} BinFileDirectory ${BinFileDirectory}"
echo "${NOW} ${PROG} LogFileDirectory ${LogFileDirectory}"
echo "${NOW} ${PROG} TempFileDirectory ${TempFileDirectory}"
echo "${NOW} ${PROG} CommonScriptFileDirectory ${CommonScriptFileDirectory}"
echo "${NOW} ${PROG} CommonLogFileDirectory ${CommonLogFileDirectory}"
echo "${NOW} ${PROG} LogFileName ${LogFileName}"
echo "${NOW} ${PROG} TEMPBATCHNBRLOG ${TEMPBATCHNBRLOG}"
echo "${NOW} ${PROG} DATASTAGEPROJECT ${DATASTAGEPROJECT}"
echo "${NOW} ${PROG} DSSERVER ${DSSERVER}"
echo "${NOW} ${PROG} DSUSERID ${DSUSERID}"
echo "${NOW} ${PROG} DSPASSWORD *Protected*"
echo
#######
####### PARAMETER BUILD Without batch number ##################################
#######
if [ "${ProcessDate}" = "NULL" ]; then
StartTimestamp=`date '+%Y-%m-%d %H:%M:%S'`
else
StartTimestamp="${ProcessDate}"
fi
ParamList=" -param ParameterFile=${ParameterFile}"
ParamList="${ParamList} -param ProcessDate="${StartTimestamp}""
ParamList="${ParamList} -param FileSetDate=${FileSetDate}"
ParamList="${ParamList} -param JobHierarchyFile=${JobHierarchyFile}"
ParamList="${ParamList} -param SourceSystemList=${SourceSystemList}"
ParamList="${ParamList} -param SubjectAreaList=${SubjectAreaList}"
ParamList="${ParamList} -param ClearWorkArea=${ClearWorkArea}"
ParamList="${ParamList} -param StartingMilestone=${StartingMilestone}"
ParamList="${ParamList} -param EndingMilestone=${EndingMilestone}"
ParamList="${ParamList} -param DebugMode=${DebugMode}"
ParamList="${ParamList} -param JobLinkStatisticChecksFile=${JobLinkStatisticChecksFile}"
ParamList="${ParamList} -param ResurrectLogFile=${ResurrectLogFile}"
#######
####### Get Batch Number and create ETL_BATCH_AUDIT record #####################
#######
echo "${NOW} ${PROG} About to get new BATCH_NBR and insert it into ETL_BATCH_AUDIT..."
${CommonScriptFileDirectory}/comPLSQL.ksh ${ParameterFile} "IRDSN" "IRUserID"
GET_NEW_BATCH_NBR
"${JobName}"
"${StartTimestamp}"
"${UserID}"
"${SourceSystemList}"
"${SubjectAreaList}"
"${ParamList}"
"${FileSetDate}" > ${TEMPBATCHNBRLOG}
SQL_EXIT_STATUS=$?
cat ${TEMPBATCHNBRLOG}
if [ "${SQL_EXIT_STATUS}" != 0 ]; then
NOW=`date`
echo "${NOW} ${PROG} Failure to connect/insert into ETL_Batch_Audit table!"
exit ${SQL_EXIT_STATUS}
fi
#######
####### Get BATCH_NBR from batch number log file ##############################
#######
BatchNumber=`grep -w BATCH_NBR ${TEMPBATCHNBRLOG}|cut -d "=" -f2`
if [ -z "${BatchNumber}" ]; then
NOW=`date`
echo "${NOW} ${PROG} Failure to retrieve BATCH_NBR from ${TEMPBATCHNBRLOG}"
exit ${SQL_EXIT_STATUS}
fi
#######
####### Add batch number to list of parameters #################################
#######
ParamList="${ParamList} -param BatchNumber=${BatchNumber}"
NOW=`date`
echo
echo ${NOW} ${PROG} Parameter list: ${ParamList}
echo
#######
####### DataStage EXECUTION ####################################################
#######
NOW=`date`
echo "${NOW} ${PROG} Executing DataStage dsjob program..."
echo ${BinFileDirectory}/dsjob -server ${DSSERVER} -user ${DSUSERID} -password ${DSPASSWORD} -run -wait ${ParamList} ${DATASTAGEPROJECT} ${JobName} 2>&1 > ${LogFileName}
echo
echo "${BinFileDirectory}/dsjob -server ${DSSERVER} -user ${DSUSERID} -password ${DSPASSWORD} -run -wait ${ParamList} ${DATASTAGEPROJECT} ${JobName} 2>&1 > ${LogFileName}"
echo
eval ${BinFileDirectory}/dsjob -server ${DSSERVER} -user ${DSUSERID} -password ${DSPASSWORD} -run -wait ${ParamList} ${DATASTAGEPROJECT} ${JobName} 2>&1 >> ${LogFileName}
jobwaiting=`grep "Waiting for job..." ${LogFileName}`
if [ "${jobwaiting}" != "Waiting for job..." ]; then
NOW=`date`
echo ${NOW} ${PROG} "DataStage failed to start the job"
failedstart=1
else
NOW=`date`
echo ${NOW} ${PROG} "DataStage successfully started the job"
failedstart=0
fi
NOW=`date`
echo ${NOW} ${PROG} "Retrieving job information"
${BinFileDirectory}/dsjob -server ${DSSERVER} -user ${DSUSERID} -password ${DSPASSWORD} -jobinfo ${DATASTAGEPROJECT} ${JobName} >> ${LogFileName}
#######
####### CHECK STATUS ###########################################################
#######
ERROR=`grep "Job Status" ${LogFileName}`
ERROR=${ERROR##*(}
ERROR=${ERROR%%)*}
if [ "${failedstart}" != 0 ]; then
NOW=`date`
echo ${NOW} ${PROG} "The job failed to start"
AuditStatus="FAILURE"
Comments="MasterControl aborted"
EXIT_STATUS=1
else
if [ "${ERROR}" = 1 -o "${ERROR}" = 2 ]; then
NOW=`date`
echo ${NOW} ${PROG} "The job completed successfully"
AuditStatus="SUCCESS"
Comments=""
EXIT_STATUS=0
else
NOW=`date`
echo ${NOW} ${PROG} "The job aborted"
AuditStatus="FAILURE"
Comments="MasterControl aborted"
EXIT_STATUS=1
fi
fi
FailedJobCount=`grep -i FAILED ${LogFileDirectory}/${JobName}.log|wc -l|cut -b1-9`
FailedJobCount=`expr ${FailedJobCount} + 0`
echo ${NOW} ${PROG} The number of failed jobs is [${FailedJobCount}]
if [ "${FailedJobCount}" != 0 ]; then
NOW=`date`
echo ${NOW} ${PROG} "The job had failed processes"
AuditStatus="FAILURE"
Comments="MasterControl had ${FailedJobCount} failed processes"
EXIT_STATUS=1
fi
StoppedJobStreamCount=`grep "JOB STREAM STOPPED" ${LogFileDirectory}/${JobName}.his|wc -l|cut -b1-9`
StoppedJobStreamCount=`expr ${StoppedJobStreamCount} + 0`
if [ "${StoppedJobStreamCount}" != 0 ]; then
NOW=`date`
echo ${NOW} ${PROG} "The job stream was STOPped or KILLed"
AuditStatus="FAILURE"
Comments="MasterControl job stream was STOPped or KILLed"
EXIT_STATUS=1
fi
#######
####### AUDIT ##################################################################
#######
echo
echo "${NOW} ${PROG} About to update ETL_BATCH_AUDIT with status information..."
EndTimestamp=`date '+%Y-%m-%d %H:%M:%S'`
SQLstring="UPDATE ETL_BATCH_AUDIT A
SET A.END_TIMESTAMP = TO_DATE('${EndTimestamp}','YYYY-MM-DD HH24:MI:SS'),
A.STATUS = '${AuditStatus}',
A.COMMENTS = '${Comments}',
A.RUNTIMESETTINGS = '${ParamList}'
WHERE (A.BATCH_NBR = ${BatchNumber});"
NOW=`date`
echo ${NOW} ${PROG} Audit SQL ${SQLstring}
SQLScriptFileName=${TempFileDirectory}/${PROG}_${JobName}_end.sql
echo ${SQLstring} > ${SQLScriptFileName}
${CommonScriptFileDirectory}/comSQLPlus.ksh ${ParameterFile} IRDSN IRUserID ${SQLScriptFileName}
SQL_EXIT_STATUS=$?
if [ "${SQL_EXIT_STATUS}" != 0 ]; then
NOW=`date`
echo ${NOW} ${PROG} Failure to connect/update into ETL_Batch_Audit table!
exit ${SQL_EXIT_STATUS}
fi
#######
####### EXIT ###################################################################
#######
NOW=`date`
echo ${NOW} ${PROG} Complete, exiting with status [${EXIT_STATUS}]
exit ${EXIT_STATUS}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11419868/viewspace-1017988/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- crontab排程Python指令碼Python指令碼
- Linux Shell指令碼時間排程Linux指令碼
- 用海豚排程器定時排程從Kafka到HDFS的kettle任務指令碼Kafka指令碼
- Oracle Windows平臺自動排程備份指令碼OracleWindows指令碼
- 使用DBMS_SCHEDULER排程作業系統shell指令碼作業系統指令碼
- DBA救火排殺指令碼指令碼
- Flink排程之排程器、排程策略、排程模式模式
- swoole 協程原始碼解讀 (協程的排程)原始碼
- datastage--dsjobAST
- Linux核心排程分析(程式排程)Linux
- Spark中資源排程和任務排程Spark
- goroutine排程原始碼閱讀筆記Go原始碼筆記
- golang 原始碼分析之scheduler排程器Golang原始碼
- 批次過程獲取指令碼指令碼
- datastage抽取工程中文亂碼解決辦法AST
- Go語言排程器之主動排程(20)Go
- Go排程器系列(3)圖解排程原理Go圖解
- go 原始碼分析 goroutine 概覽與排程Go原始碼
- Golang的GMP排程模型與原始碼解析Golang模型原始碼
- 單個過程獲取指令碼指令碼
- 排程器簡介,以及Linux的排程策略Linux
- Go排程器系列(2)巨集觀看排程器Go
- Go語言排程器之排程main goroutine(14)GoAI
- 【Spark篇】---Spark資源排程和任務排程Spark
- Pod的排程是由排程器(kube-scheduler)
- Go runtime 排程器精講(五):排程策略Go
- 任務排程
- 資料排程
- spark排程管理Spark
- async-await:協作排程 vs 搶佔排程AI
- k8s排程器介紹(排程框架版本)K8S框架
- libgo原始碼分析之多執行緒協程管理和排程Go原始碼執行緒
- Linux程式排程邏輯與原始碼分析Linux原始碼
- 儲存過程批量生成awr指令碼儲存過程指令碼
- 全表複製過程建立指令碼指令碼
- 2.2.5排程演算法:時間片輪轉、優先順序排程、多級反饋排程演算法
- Golang原始碼學習:排程邏輯(三)工作執行緒的執行流程與排程迴圈Golang原始碼執行緒
- [典藏版] Golang 排程器 GMP 原理與排程全分析Golang