Parallel processing xargs并行-捕获退出代码

Parallel processing xargs并行-捕获退出代码,parallel-processing,Parallel Processing,我有一个shell脚本,它解析一个平面文件,并为其中的每一行并行执行一个配置单元脚本 xargs -P 5 -d $'\n' -n 1 bash -c ' IFS='\t' read -r arg1 arg2 arg 3<<<"$1" eval "hive -hiveconf tableName=$arg1 -f ../hive/LoadTables.hql" 2> ../path/LogFile-$arg1 ' _ < ../pat

我有一个shell脚本,它解析一个平面文件,并为其中的每一行并行执行一个配置单元脚本

    xargs -P 5 -d $'\n' -n 1 bash -c '
    IFS='\t' read -r arg1 arg2 arg 3<<<"$1"
    eval "hive -hiveconf tableName=$arg1 -f ../hive/LoadTables.hql" 2> ../path/LogFile-$arg1
    ' _ < ../path/TableNames.txt
xargs-p5-d$'\n'-n1bash-c'

如果s='\t'read-r arg1 arg2 arg3我想您应该寻找更有趣的东西,但一个简单的解决方案是将可能的错误存储在tmp文件中,然后再查找:

FilewithErrors=/tmp/errors.txt
FinalError=0

xargs -P 5 -d $'\n' -n 1 bash -c '
IFS='\t' read -r arg1 arg2 arg 3<<<"$1"
eval "hive -hiveconf tableName=$arg1 -f ../hive/LoadTables.hql || echo $args1 > $FilewithErrors" 2> ../path/LogFile-$arg1
' _ < ../path/TableNames.txt

if [ -e $FilewithErrors ]; then FinalError=1; fi

rm $FilewithErrors

return $FinalError
FilewithErrors=/tmp/errors.txt
最终错误=0
xargs-p5-d$'\n'-n1bash-c'

IFS='\t'根据注释读取-r arg1 arg2 arg3:使用GNU并行安装作为个人安装或最小安装,如中所述

manparallel

退出状态

   Exit status depends on --halt-on-error if one of these are used: success=X,
   success=Y%, fail=Y%.

   0     All jobs ran without error. If success=X is used: X jobs ran without
         error. If success=Y% is used: Y% of the jobs ran without error.

   1-100 Some of the jobs failed. The exit status gives the number of failed jobs.
         If Y% is used the exit status is the percentage of jobs that failed.

   101   More than 100 jobs failed.

   255   Other error.
如果需要确切的错误代码(而不仅仅是作业是否失败),请使用:
--joblog mylog

您可能可以执行以下操作:

cat ../path/TableNames.txt |
  parallel --colsep '\t' --halt now,fail=1 hive -hiveconf tableName={1} -f ../hive/LoadTables.hql '2>' ../path/LogFile-{1}
如果一个作业失败,
fail=1
将停止生成新作业,并使用该作业的退出代码退出


现在
将终止剩余的作业。如果您希望剩余的作业退出“自然原因”,请尽快使用

能否详细说明为什么不能使用GNU并行?原因在上面吗?谢谢你提供的信息。我认为我们必须安装gnu并行(我们不允许安装任何软件)才能使用它。从未意识到有复制并行文件并使用它的选项。我们终于在我们的环境中安装了gnu并行。目前,我上面的脚本使用xargs,如何将其替换为parallel,执行与解析平面文件相同的操作,并对其中的每一行并行执行一个配置单元脚本,其中包含退出状态捕获和失败逻辑。谢谢