GNU 并行和 pwd 之外的基本文件?

GNU 并行和 pwd 之外的基本文件?

我正在使用 GNU 并行在远程主机上执行计算量大的转换,这些转换比请求工作的主机更强大。

我正在使用位于 的 bash 脚本/usr/local/lib/myscript,并且我想在远程主机上使用它。但是,我不想要求主机拥有此脚本,因此我将其与--basefile.

如果我只提供文件名,一切都会顺利。但如果我提供基本文件的完整路径,它就不起作用。

为了显示:

$ cat /tmp/common.sh
#!/usr/bin/env bash
echo "Hello world! from $(hostname)"

$ cd /tmp
$ parallel --nonall -S 2/user@remote-host --basefile common.sh --cleanup bash common.sh
Hello world! from remote-host

$ parallel --nonall -S 2/user@remote-host --basefile     /tmp/common.sh --cleanup "bash {}"
could not make way for new symlink: tmp
rsync error: some files could not be transferred (code 23) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-47/rsync/main.c(992) [sender=2.6.9]
cannot delete non-empty directory: tmp

有没有办法使用--basefile当前路径之外的文件?或者我应该使用第二个--trc并利用{1}{2}替换模式来模拟--basefile

答案1

--basefile, --transfer-file, --transfer, --returnGNU Parallel 中的文件传输(即)使用了rsync/./ 魔法。因此,当您要求传输时,/tmp/common.sh它将被放入/tmp/common.sh远程端。但如果您要求转移,/tmp/./common.sh它将转移/tmp/common.sh$(pwd)/..

换句话说:

(local file) => (remote file)
dir/file => ./dir/file
/tmp/sub/dir/file => /tmp/sub/dir/file
/tmp/sub/./dir/file => ./dir/file

您看到的错误可能是由于 /tmp 是远程系统上的符号链接所致。

如果您使用,--workdir ...每个作业都会有新的工作目录。由于--basefile仅在第一个作业运行之前复制文件,因此这不起作用。

相反,您可以为每个作业传输 common.sh:

parallel --wd ... --tf {1} -S server 'pwd ; ls; echo {2}' ::: /tmp/./common.sh ::: foo bar

相关内容