同时读取循环

时间:2017-10-03 12:53:45

标签: bash while-loop parallel-processing

我在bash脚本中有以下while循环但是我想并行运行这些(失败)有人能指出我正确的方向吗?

谢谢!

while read LINE; do
    RAYID=$(echo "$LINE" | jq -r .rayId)
    LINE="$(echo $LINE | sed 's/\([[:digit:]]\{13\}\)[[:digit:]]\{6\}/\1/g')"
    args=( -XPUT "localhost:9200/els/logs/$RAYID?pipeline=geoip-els" -H "Content-Type: application/json" -d "$LINE" )
    curl "${args[@]}" > /dev/null 2>&1
done <<< "$ELS_LOGS"

1 个答案:

答案 0 :(得分:1)

**已编辑

除了@TomFenech所说的正确之外,我想补充一点,如果你在 done function doSomething(){ RAYID=$(echo "$1" | jq -r .rayId ) LINE="$(echo $1 | sed 's/\([[:digit:]]\{13\}\)[[:digit:]]\{6\}/\1/g' )" args=( -XPUT "localhost:9200/els/logs/$RAYID?pipeline=geoip-els" -H "Content-Type: application/json" -d "$1" ) curl "${args[@]}" > /dev/null 2>&1 } while read LINE; do doSomething $LINE & done <<< "$ELS_LOGS" wait 也会很好>,所以在完成所有任务之前,脚本将无法完成执行。

df = pd.DataFrame([[3,3,3]]*4,index=['a','b','c','d'])

问候!