在使用datastage抽取資料的過程中,經常會遇到要求以准即時(如每隔3分鐘同步一次資料)進行資料幫浦的需求。這些要求可以使用crontab+shell來實現。如所示,此為整個shell調度DS JOB的流程:首先使用dsjob的jobinfo參數擷取該JOB的進程號(process_id)和狀態值(state).當state異常時,重設該JOB;當state正常時,判斷該job是否在運行(即process_id是否為0)。若process_id=0,表示目前該JOB未運行,正常調度該JOB,若process_id>0,表示該JOB正在運行階段,轉置結束處。
代碼如下:
#!/bin/sh. /home/dsadm/.bash_profileAPT_CONFIG_FILE=/opt/IBM/InformationServer/Server/Configurations/default.aptPROJECT_NAME=$1JOB_NAME=$2#job stat flagstatus=1job_process_id=1cd $DSHOME/bin#check job status job_process_id=`./dsjob -jobinfo "$PROJECT_NAME" "$JOB_NAME"|sed -n '10,1p'|sed 's/\(.*\)\([:]\)\([ ]\{1,\}\)\([0-9]\{1,\}\)/\4/g'` ./dsjob -jobinfo $PROJECT_NAME $JOB_NAME echo "job_process_id=dsjob -jobinfo $PROJECT_NAME $JOB_NAME" status=`./dsjob -jobinfo $PROJECT_NAME $JOB_NAME|sed -n '1,1p'|sed 's/\(.*\)\([:]\)\([ ]\{1,\}\)\(.*\)/\4/g'|grep FAILED|wc -l` echo "status=dsjob -jobinfo $PROJECT_NAME $JOB_NAME"if [ $status -ne 0 ]; then ./dsjob -run -mode RESET $PROJECT_NAME $JOB_NAME echo "Invoke: dsjob -run -mode RESET $PROJECT_NAME $JOB_NAME" else if [ "$job_process_id" -eq 0 ]; then ./dsjob -run -param \$APT_CONFIG_FILE="$APT_CONFIG_FILE" $PROJECT_NAME $JOB_NAME fifiecho "Finished"
然後,通過crontab進行上述指令碼的調度,即可。