0

我对 shell 脚本和 UNIX 比较陌生。我正在使用 Solaris 机器,问题是我们有一个名为的 shell 脚本strtwrfl.sh,它接受一个参数作为工作流名称并启动工作流,例如工作流名称./strtwrfl.sh ABC在哪里ABC

我必须运行 200 多个这样的工作流,每个工作流都依赖于前一个工作流的成功完成,即如果有 2 个工作流ABC,只有成功BCD执行strtwrfl.sh BCD才会strtwrfl.sh ABC成功。

每个工作流需要不同的时间才能成功执行。

我必须编写一个 shell 脚本,这样 200 多个 informatica 工作流必须(我不介意将这些工作流手动输入脚本)一个接一个地执行,如果一个失败,脚本应该停止显示哪个工作流失败。

由于这是一个生产环境,我将无法在strtwrfl.sh这里分享。

4

3 回答 3

2

我不确定我是否正确理解了您的问题,但是如果您只想使用不同的参数连续多次调用脚本并在执行失败时终止,您可以执行以下操作:

meta_strtwrfl.sh

#!/bin/sh

script="./strtwrt.sh"
workflows="
        ABC
        BCD
        CDE
"

for workflow in ${workflows}; do
        "${script}" "${workflow}" || { echo "$0: workflow '${workflow}' failed!"; exit 1; }
done
echo "$0: all workflows finished successfully!"

更改script="./strtwrt.sh"以反映strtwrt.sh脚本的路径并进行workflows相应更改。我不知道您的 solaris 系统上有哪个标准 shell,因此我们不使用数组作为workflow变量,这意味着您的工作流名称不能以这种方式包含空格。

示例运行:

$ ./meta_strtwrfl.sh
./meta_strtwrfl.sh: all workflows finished successfully!

$ ./meta_strtwrfl.sh
./meta_strtwrfl.sh: workflow 'ABC' failed!
于 2013-04-29T19:00:34.770 回答
0

这不应该真的很简单......在一行中输入这些条目中的每一个......一个接一个......

./strtwrfl.sh ABC ./strtwrfl.sh ABC1 ./strtwrfl.sh ABC2 .. .. ..

等等..

那将是赤裸裸的骨头..

然后,您可以通过进行错误处理来即兴发挥这一点。

还是您想实现不同的目标?我无法从问题描述中找到?

于 2013-04-29T14:22:11.993 回答
-1
<<'notrequired'               
            wfrunid=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run id" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
                        cur_wf_status=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run status" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`

                        if [ "${cur_wf_status}" == "Suspended" ] 
                            then
                                echo "Workflow $workflow_name  Status :${cur_wf_status}"  
                                echo "Workflow $workflow_name Runid :${wfrunid}"  
                                echo "                                              " 
                                echo "######################################## Running workflow in Re-START mode start ################################" 
                                echo "#################################################################################################################" 
                                echo "#################################################################################################################" 


                                pmcmd recoverworkflow -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -paramfile ${param_file} -rin ${RUN_INSTANCE} -wfrunid ${wfrunid} ${workflow_name} 

                                if [ $?  -ne  0 ]
                                    then 
                                           echo "################################################# END OF LOG ####################################################" 
                                           exit 1
                                fi                                          
                                while (true)
                                    do
                                        rec_wf_status=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run status" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`

                                        rec_wf_log_name=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE}  ${workflow_name} | grep "Workflow log file" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`

                                        case "${rec_wf_status}" in
                                        ("Suspended"|"Failed"|"Aborted"|"Stopped") sleep 10

                                        rec_wf_error_start=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE}  ${workflow_name} | sed -n '/Workflow run error message: /=' | sed -n '$p' 2> /dev/null`

                                        rec_w_error_end=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n '/Start time: /=' | sed -n '$p' 2> /dev/null`

                                        rec_wf_error_end=`expr $rec_w_error_end - 1 2>/dev/null`

                                        rec_wf_error=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n "$rec_wf_error_start,$rec_wf_error_end p" 2> /dev/null`





                        rec_task_name=`echo ${wf_error} | sed 's/\(^.*task instance\)\(.*\)\(].*$\)/\2/' | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`

                                        rec_task_type=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | grep "Task type:" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`

                                        rec_task_error_start=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n '/Task run error message: /=' | sed -n '$p' 2>/dev/null` 

                                        rec_error_end=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n '/Integration Service: /=' | sed -n '$p' 2>/dev/null`

                                        rec_task_error_end=`expr $rec_error_end - 1 2> /dev/null`

                                        rec_task_error=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n "${rec_task_error_start},${rec_task_error_end} p" 2> /dev/null`

                                        print_error=`echo "Task ${rec_task_name} Failed"`

                                        case "${rec_task_type}" in
                                          ("Session") print_error=`echo "${rec_task_name} ${rec_task_error}"`
                                          esac
                                         esac 

                                        case "$rec_wf_status" in 
                                        "Suspended") echo "                     " 
                                               echo "Workflow Status  : ${rec_wf_status}"  
                                               echo "                     " 
                                               echo "################################################ WORKFLOW ERROR #################################################" 
                                               echo "                     " 
                                               echo "WORKFLOW ${rec_wf_error}" 
                                               echo "                     " 
                                               echo "################################################# TASK ERROR ####################################################" 
                                               echo "                     " 
                                               echo "Task Type: ${rec_task_type}" 
                                               echo "                     " 
                                               echo "${print_error}" 
                                               echo "                     " 
                                               execution_stop_time=`date "+%d-%m-%Y-%T"`
                                               echo "Execution Stop Time : $execution_stop_time" 
                                               echo "                     " 
                                               echo "################################################# END OF LOG ####################################################" 
                                               exit 1
                                               ;;
                                        "Succeeded") echo "                     " 
                                               echo "Workflow Status  : ${rec_wf_status}"  
                                               echo "                     " 
                                               echo "Workflow Run Successfully Completed"  
                                               echo "                     " 
                                               execution_stop_time=`date "+%d-%m-%Y-%T"`
                                               echo "Execution Stop Time : $execution_stop_time" 
                                               echo "                     " 
                                               echo "################################################# END OF LOG ####################################################" 
                                               exit 0
                                               ;;
                                        "Aborted") echo "                     "   
                                               echo "Workflow Status  : ${rec_wf_status}"  
                                               echo "                     " 
                                               echo "################################################ WORKFLOW ERROR #################################################" 
                                               echo "                     " 
                                               echo "WORKFLOW ${rec_wf_error}" 
                                               echo "                     " 
                                               echo "################################################# TASK ERROR ####################################################" 
                                               echo "Task Type: ${rec_task_type}" 
                                               echo "                     " 
                                               echo "                     " 
                                               echo "${print_error}" 
                                               echo "                     " 
                                               execution_stop_time=`date "+%d-%m-%Y-%T"`
                                               echo "Execution Stop Time : $execution_stop_time" 
                                               echo "                     " 
                                               echo "################################################# END OF LOG ####################################################" 
                                               exit 1
                                               ;;
                                        "Failed") echo "                     "  
                                               echo "Workflow Status  : ${rec_wf_status}"  
                                               echo "                     " 
                                               echo "################################################ WORKFLOW ERROR #################################################" 
                                               echo "                     " 
                                               echo "WORKFLOW ${rec_wf_error}" 
                                               echo "                     " 
                                               echo "################################################# TASK ERROR ####################################################" 
                                               echo "Task Type: ${rec_task_type}" 
                                               echo "                     " 
                                               echo "                     " 
                                               echo "${print_error}" 
                                               echo "                     " 
                                               execution_stop_time=`date "+%d-%m-%Y-%T"`
                                               echo "Execution Stop Time : $execution_stop_time" 
                                               echo "                     " 
                                               echo "################################################# END OF LOG ####################################################" 
                                               exit 1
                                               ;;
                                        "Stopped") echo "                     "   
                                               echo "Workflow Status  : ${rec_wf_status}"  
                                               echo "                     " 
                                               echo "################################################ WORKFLOW ERROR #################################################" 
                                               echo "                     " 
                                               echo "WORKFLOW ${rec_wf_error}" 
                                               echo "                     " 
                                               echo "################################################# TASK ERROR ####################################################" 
                                               echo "Task Type: ${rec_task_type}" 
                                               echo "                     " 
                                               echo "                     " 
                                               echo "${print_error}" 
                                               echo "                     " 
                                               execution_stop_time=`date "+%d-%m-%Y-%T"`
                                               echo "Execution Stop Time : $execution_stop_time" 
                                               echo "                     " 
                                               echo "################################################# END OF LOG ####################################################" 
                                               exit 1
                                               ;;          
                                        esac

                                    done    

                        else
notrequired
于 2016-08-11T10:46:51.880 回答