linux shell 同时执行,bash – 同时执行多个shell脚本

这是我一直在运行的一些代码,它们似乎完全符合您的要求.只需在适当的位置插入./a.sh和./b.sh:

# Start the processes in parallel...

./script1.sh 1>/dev/null 2>&1 &

pid1=$!

./script2.sh 1>/dev/null 2>&1 &

pid2=$!

./script3.sh 1>/dev/null 2>&1 &

pid3=$!

./script4.sh 1>/dev/null 2>&1 &

pid4=$!

# Wait for processes to finish...

echo -ne "Commands sent... "

wait $pid1

err1=$?

wait $pid2

err2=$?

wait $pid3

err3=$?

wait $pid4

err4=$?

# Do something useful with the return codes...

if [ $err1 -eq 0 -a $err2 -eq 0 -a $err3 -eq 0 -a $err4 -eq 0 ]

then

echo "pass"

else

echo "fail"

fi

请注意,这会捕获脚本的退出状态,而不是它输出到stdout的内容.没有简单的方法来捕获在后台运行的脚本的标准输出,因此我建议您使用exit status将信息返回给调用进程.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值