processUsageFile()
{
#sdate=`pin_virtual_time | awk -F" " '{print $3}'`;
#Get all new files to be loaded to brm staging data.
count=`ls ${PRE_STAGING}/TWN* 2>/dev/null|grep -v reprocess|wc -l`
if [ $count -ne 0 ];then
# Fork subshell
(./efx_omc_brm_rpt_process.sh -t TWN & )&
exitOnError
fi
#Process Rapid Report files
count=`ls $PRE_STAGING/RR* 2>/dev/null|grep -v reprocess|wc -l`
if [ $count -ne 0 ];then
(./efx_omc_brm_rpt_process.sh -t RR &)&
exitOnError
fi
...
...
}
#Reprocessing. Process the reprocessed files.
#This method updates the records in the BRM staging table.
reprocessingUsageFile()
{
#Process TWN fulfillment reprocess files
count=`ls $PRE_STAGING/TWN*reprocess* 2>/dev/null|wc -l`
if [ $count -ne 0 ];then
# Fork subshell
(./efx_omc_brm_rpt_reprocess.sh -t TWN & ) &
fi
#Process Rapid Report files
count=`ls $PRE_STAGING/RR*reprocess* 2>/dev/null|wc -l`
if [ $count -ne 0 ];then
(./efx_omc_brm_rpt_reprocess.sh -t RR &) &
fi
...
...
}
#Pre processing
PreProcessing
# Start processing usage files.
processUsageFile
processErrFile
The idea of the above code is do parallel processing. All methods invoke multiple subshells and detach from tty. I would like to know if there is way to wait for first two methods to complete execution first and then run the last method.
Waiting for PIDs is somehow not accurate. Still trying...
waitPids() {
echo "Testing $pids -- ${#pids[@]}"
while [ ${#pids[@]} -ne 0 ]; do
local range=$(eval echo {0..$((${#pids[@]}-1))})
local i
for i in $range; do
if ! kill -0 ${pids[$i]} 2> /dev/null; then
echo "Done -- ${pids[$i]}"
unset pids[$i]
fi
done
pids=("${pids[@]}")
sleep 1
done
}