如何使用GNU Parallel

时间:2015-11-16 19:53:21

标签: bash parallel-processing gnu gnu-parallel

如何将GNU parallel与aws sync命令一起使用?

我有一个包含以下命令的文件:

aws s3 cp ./test s3://test --recursive --content-encoding "gzip" --content-type "text/html" --cache-control "max-age=$MAXAGE" --exclude "*" --include "*.html" --profile $PROFILE

aws s3 cp ./test s3://test  $S3BUCKET --recursive --content-encoding "gzip" --content-type "text/html" --cache-control "max-age=$MAXAGE" --exclude "*" --include "*.css" --profile $PROFILE

如何使用GNU parallel并行运行这些命令?

我所做的是在名为test.sh

的文件中添加命令

我运行以下命令

parallel < test.sh

] 如何将参数传递给test.sh文件?例如,我想传入aws存储桶名称。

2 个答案:

答案 0 :(得分:2)

如果你的目标是在一组手写命令的任何成员失败时触发脚本失败,那么GNU parallel并不是这项工作的最佳工具:shell本身已经提供了{{1}所需的一切。 } command,which is specified by POSIX and present out-of-the-box on all standards-compliant shells(另请参阅规范requiring it to be implemented as a builtin)。

wait

请注意,为方便起见,上面使用了数组,而不是必需;您可以使用函数提供公共参数,和/或在标量变量中构建PID数组,或者如果您的目标是编写可在任何POSIX基线shell上运行的代码,则在shell函数内覆盖“$ @”。

答案 1 :(得分:0)

您可以通过导出所有必需的变量,然后将命令传递给parallel,并在此处引用一个引用来执行此操作:

#!/bin/bash
export S3BUCKET="$1"
export MAXAGE=42
export PROFILE=foobar

parallel --gnu << 'EOF'
aws s3 cp ./test s3://test --recursive --content-encoding "gzip" --content-type "text/html" --cache-control "max-age=$MAXAGE" --exclude "*" --include "*.html" --profile $PROFILE
aws s3 cp ./test s3://test  $S3BUCKET --recursive --content-encoding "gzip" --content-type "text/html" --cache-control "max-age=$MAXAGE" --exclude "*" --include "*.css" --profile $PROFILE
EOF