我如何使用并行选项时通过多个子命令的xargs [英] How can I pass multiple sub-commands to xargs when using the parallel option

查看:183
本文介绍了我如何使用并行选项时通过多个子命令的xargs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个bash脚本来处理大型目录树和rsync,在多个数据流。从这个网站的其他研究,我构建了以下内容。假设是运行命令:

I'm trying to write a bash script to process a large directory tree and rsync that in multiple streams. From other research on this site I constructed the following. The assumption is the command is run:

program.sh /输入/位置/输出/位置$线程

program.sh /input/location /output/location $threads

在我的剧本的关键行是

cd $1; find . -depth \( -type d -printf \""%p/\"\n" \) | xargs -n1 -P$3 -I% rsync -lptgoDds --delete --backup --backup-dir=$INCREMENTALS/$DATE/$1 % $2/%

的上述的想法是在某一点,找到所有的目录,然后将它们传递给平行的rsync命令的实例从$ 1中的数据复制到$ 2

The idea of the above is to find all the directories at a certain point and then pass them to parallel instances of an rsync command to copy the data from $1 to $2.

我遇到的问题是rsync的可能要创建尚未取决于投入是如何解析的存在嵌套的文件夹。 (至少我认为这就是我看到的错误的原因)。为了解决这个问题,我想我可以发出的rsync中的两个命令。第一个命令将使目录中,第二个启动的rsync。

The issue I am having is rsync may have to create nested folders that don't yet exist depending on how the inputs are parsed. (At least I think that's the cause of the errors I'm seeing). To get around this I thought I could issue two commands within the rsync. The first command would make the directory, the second would start the rsync.

事情是这样的:

cd $1; find . -depth \( -type d -printf \""%p/\"\n" \) | xargs -n1 -P$3 -I% 'mkdir -p %;rsync -lptgoDdsv --delete % $2/%;'

但是,这似乎并没有任何工作。

But that doesn't seem to work either.

所以,有玩这个有一段时间了,我伸手求助。 : - )

So having played with this for some time now, I'm reaching out for help. :-)

推荐答案

您无法通过在单引号一个复杂的命令的xargs 这样。但是你可以把它传递给 SH ,并传递给的xargs

You cannot pass a complex command in single quotes to xargs like that. But you can pass it to sh, and pass that to xargs.

cd $1; find . -depth \( -type d -printf \""%p/\"\n" \) | xargs -n1 -P$3 -I% sh -c 'mkdir -p %;rsync -lptgoDdsv --delete % $2/%;'

(我没有办法来测试这一点。它可能还需要一些调整。)

(I have no way to test this. It might still need some adaptation.)

这篇关于我如何使用并行选项时通过多个子命令的xargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆