并行调用多个功能在Bash脚本中间歇性地工作。
我正在尝试在bash脚本中并行调用多个函数。
所有功能都包含相同的代码和逻辑,但是功能call_bpa
和call_inv
间歇地工作。
出现错误[:函数call_bpa或call_inv中期望的参数。
提交CPA计划。 如果CPA计划已完成, 并行调用函数call_po,call_bpa和call_inv。 如果call_po和call_inv完成,则 调用函数call_chk 万一; 万一; 检查所有功能是否完成,然后
#!/bin/ksh
p_userid=$2
p_max_runtime=$5
p_apps_pwd=$6
p_resp_name=$7
p_sleeptime=$8
# removing temp file of the previous run
if [ -f XXPRP_PATH/PRGPOPULATE_CTRL_FILE ]
then
echo "$(date) - removing temp file of the previous run "
rm -r XXPRP_PATH/PRGPOPULATE_CTRL_FILE
fi
logfile=$(mktemp XXPRP_PATH/PRGPOPULATE_CTRL_FILE)
chmod 777 XXPRP_PATH/PRGPOPULATE_CTRL_FILE
call_bpa()
{
-- bpa program submission logic
echo 1 >> $logfile
}
call_po()
{
--po program submission logic
echo 2 >> $logfile
}
call_inv()
{
--inv program submission logic
echo 3 >> $logfile
}
call_chk()
{
--chk program submission logic
echo 4 >> $logfile
}
p_pop_max_wait=$(( p_max_runtime * 60 * 60 ))
echo "$(date) - Max wait for the weekend run is $p_pop_max_wait secs"
--CPA program submission logic
# If CPA program completed, the only submit rest of the programs
if [ $p_phase_code = "C" ]
then
call_bpa & call_po & call_inv
lv_chk_exit="N"
waittime=0
while ! grep "1" $logfile || ! grep "3" $logfile
do
echo "$(date) - Waiting for INV or BPA program to complete "
sleep $p_sleeptime
waittime=`expr $waittime + $p_sleeptime`
if [ "$waittime" -eq "$p_pop_max_wait" ]
then
lv_chk_exit="Y"
exit 0
fi
done
fi
# If INV and BPA functions, the only submit chk request set
if [ $lv_chk_exit = "N" ]
then
call_chk
fi
lv_cons_exit='N'
waittime=0
while ! grep "1" $logfile || ! grep "2" $logfile || ! grep "3" $logfile
do
echo "$(date) - Waiting for all the Parent request sets to complete "
sleep $p_sleeptime
waittime=`expr $waittime + $p_sleeptime`
if [ "$waittime" -eq "$p_pop_max_wait" ]
then
lv_cons_exit="Y"
exit 0
fi
done
echo "$(date) - removing temp file created"
rm -r $logfile
echo "$(date) - Population Program request sets completed successfully"
# Program submission logic which is referred in each function
call_bpa()
{
# submit Purge Populate BPA STG tables request set
p_request_set=`sqlplus -s <<EOF
apps/$p_apps_pwd
set serveroutput on
DECLARE
l_success boolean;
e_submit_failed exception;
l_request_set_id number;
BEGIN
fnd_global.apps_initialize($p_userid,$p_resp_id,$p_resp_appl_id);
l_success:=fnd_submit.set_request_set('XXPRP','XXPRPBPAPOPLTSTG');
IF not l_success then
raise e_submit_failed;
END IF;
l_success := fnd_submit.submit_program ('XXPRP', 'XXPRPPOPULTBPASTG','STGBPA10');
IF not l_success then
raise e_submit_failed;
END IF;
l_success := fnd_submit.submit_program ('XXPRP', 'XXPRPPOPULTCUSTOMSTG', 'STGBPA20','BPA');
IF not l_success then
raise e_submit_failed;
END IF;
l_request_set_id := fnd_submit.submit_set (NULL, FALSE);
dbms_output.put_line(l_request_set_id);
EXCEPTION
when e_submit_failed then
dbms_output.put_line('FAILED');
END;
/
exit
EOF`
p_request_set_id=`echo $p_request_set | cut -f1 -d" "`
if [ $p_request_set_id = "FAILED" ]
then
echo "$(date) - Program exiting "
exit 1
fi
echo "$(date) - BPA STG tables Request ID: $p_request_set_id submitted sucessfully"
waittime=0
while [ "$p_bpa_phase_code" != "C" ]
do
p_req_codes=`sqlplus -s <<EOF
apps/$p_apps_pwd
set feedback off
set heading off
SELECT phase_code,status_code
FROM fnd_concurrent_requests
WHERE request_id = $p_request_set_id;
exit
EOF`
p_bpa_phase_code=`echo $p_req_codes | cut -f1 -d" "`
p_status_code=`echo $p_req_codes | cut -f2 -d" "`
if [ $p_bpa_phase_code != "C" ]
then
sleep $p_sleeptime
waittime=`expr $waittime + $p_sleeptime`
if [ "$waittime" -eq "$p_pop_max_wait" ]
then
echo "$(date) - BPA STG concurrent request set $p_request_set_id has not completed after maximum wait time of $p_pop_max_wait seconds with status_code of $p_status_code"
exit 0
fi
fi
done
if [ $p_status_code = "E" ]
then
echo "$(date) - BPA STG concurrent request set $p_request_set_id has completed with a status of ERROR"
exit 1
elif [ $p_status_code = "W" ]
then
echo "$(date) - BPA STG concurrent request set $p_request_set_id has completed with a status of WARNING"
fi
echo "$(date) - PRaP Purge Populate BPA STG concurrent request set $p_request_set_id has completed successfully"
echo 1 >> $logfile
}
答案 0 :(得分:2)
在任何类似bourne的外壳上...
cpa_program() { echo cpa_program; }
call_po() { echo call_po; }
call_bpa() { echo call_bpa; }
call_inv() { echo call_inv; }
call_chk() { echo call_chk; }
cpa_program
{
call_po &
call_inv &
wait
call_chk
} &
call_bpa &
wait
echo completed
您可以在上面的任何函数中放置sleep 1;
,以查看并行性如何工作。
&
来序列化所有内容。先尝试一下,然后在完全执行串行执行后并行化。&
位于编写的每一行的末尾。单行执行call_po & call_inv & call_foo
是不正确的。wait
的调用很重要-它们会阻止,直到并行执行步骤完成。