脚本并行执行开多个进程、使用&和wart执行
脚本getRefundfile.sh
#!/bin/bash
#
#####################################
#@file getRefundfile.sh
#@brief 获取退款对账文件、并检查文件
#@author xiajing
#@version 1.0
#@date 2017-08-21
#@log ./getRefundfile_log.log
#####################################
ar=( Jike.OffLineRefund JilinMini.AllBeREFUND JilinMini.AllREFUND Mini.AllBeREFUND Mini.AllREFUND Self.OffLineRefund UPAY.OnLineRefund )
for (( i = 0; i < ${#ar[@]}; ++i ))
do
{
date && echo ${ar[i]} && sleep 10
if [ "${ar[i]}" == 'UPAY.OnLineRefund' ]
then
sleep 30
fi
date
}&
done
wait
echo "执行完毕"
[ecs_platform@bj-ecs-jm429-D-a2-1-m610-2-null-7 GetRefundFile]$ sh getRefundfile.sh
Mon Aug 21 14:50:13 CST 2017
Mon Aug 21 14:50:13 CST 2017
Mon Aug 21 14:50:13 CST 2017
Mon Aug 21 14:50:13 CST 2017
JilinMini.AllBeREFUND
Mon Aug 21 14:50:13 CST 2017
Mini.AllBeREFUND
Jike.OffLineRefund
JilinMini.AllREFUND
Mon Aug 21 14:50:13 CST 2017
Mini.AllREFUND
Mon Aug 21 14:50:13 CST 2017
UPAY.OnLineRefund
Self.OffLineRefund
Mon Aug 21 14:50:23 CST 2017
Mon Aug 21 14:50:23 CST 2017
Mon Aug 21 14:50:23 CST 2017
Mon Aug 21 14:50:23 CST 2017
Mon Aug 21 14:50:23 CST 2017
Mon Aug 21 14:50:23 CST 2017
Mon Aug 21 14:50:53 CST 2017
执行完毕
这里需要说明一下wait的作用。wait是等待前面的后台任务全部完成才往下执行,否则程序本身是不会等待的,这样对后面依赖前面任务结果的命令来说就可能出错
阅读(2753) | 评论(0) | 转发(0) |