Вызов нескольких параллельных функций периодически работает в скрипте Bash.
Я пытаюсь вызвать несколько функций параллельно в скрипте bash.Все функции содержат одинаковый код и логику, но функции call_bpa
и call_inv
работают с перебоями.получение ошибки [: ожидается аргумент в функции call_bpa или call_inv.
Flow:
Отправка программы CPA.Если программа CPA завершена, то параллельно вызывать функции call_po, call_bpa, call_inv.Если вызовы call_po и call_inv завершены, тогда вызывается функция call_chk end if;конец если;проверьте все выполненные функции, затем
печать завершена.
#!/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
}