将 GNU Parallel 和 rsync 与密码一起使用?

Using GNU Parallel and rsync with passwords?

我已经看到 GNU parallel with rsync,不幸的是,我看不到我的用例的明确答案。

作为我脚本的一部分,我有这个:

echo "file01.zip
file02.zip
file03.zip
" | ./gnu-parallel --line-buffer --will-cite \
-j 2 -t --verbose --progress --interactive \
 rsync -aPz {} user@example.com:/home/user/

所以,我 运行 脚本,作为其输出的一部分,一旦它到达 gnu-parallel 步骤,我得到这个(因为我有 --interactive,我得到确认每个文件的提示:

rsync -aPz file01.zip user@example.com:/home/user/ ?...y
rsync -aPz file02.zip user@example.com:/home/user/ ?...y

Computers / CPU cores / Max jobs to run
1:local / 4 / 2

Computer:jobs running/jobs completed/%of started jobs/Average seconds to complete
local:2/0/100%/0.0s

...然后,进程就挂在这里什么都不做;没有数字变化或任何东西。

此时,我可以从另一个终端执行此操作:

$ ps axf | grep rsync
12754 pts/1    S+     0:00  |       |   \_ perl ./gnu-parallel --line-buffer --will-cite -j 2 -t --verbose --progress --interactive rsync -aPz {} user@example.com:/home/user/
12763 pts/1    T      0:00  |       |       \_ rsync -aPz file01.zip user@example.com:/home/user/
12764 pts/1    R      0:11  |       |       |   \_ ssh -l user example.com rsync --server -logDtprze.iLs --log-format=X --partial . /home/user/
12766 pts/1    T      0:00  |       |       \_ rsync -aPz file02.zip user@example.com:/home/user/
12769 pts/1    R      0:10  |       |           \_ ssh -l user example.com rsync --server -logDtprze.iLs --log-format=X --partial . /home/user/

... 所以我确实可以确认进程已经启动,但它们显然没有做任何事情。至于确认他们没有做任何事情(而不是上传,在这种情况下他们应该做的),我 运行 监视器 sudo iptraf,它报告所有 0 Kb/s wlan0 上的流量,这是我这里唯一的一个。

问题是 - 我登录的服务器只接受带密码的 SSH 身份验证。起初我以为 --interactive 会允许我交互式输入密码,但它提示 the user about whether to run each command line and read a line from the terminal. Only run the command line if the response starts with 'y' or 'Y'.。好吧,上面我回答了y,但之后它没有提示我输入密码,而且似乎进程挂在那里等待它。我的版本是 "GNU parallel 20160422".

$ ./gnu-parallel --version | head -1
GNU parallel 20160422

那么,我如何使用 GNU parallel,运行 多个 rsync 带有密码的任务?

使用sshpass:

doit()  {
  rsync -aPz -e "sshpass -p MyP4$$w0rd ssh" "" user@example.com:/home/user
}
export -f doit
parallel --line-buffer -j 2 --progress doit ::: *.zip

运行 并行交互式程序的根本问题是:如果两个程序都准备好输入,哪个程序应该获得输入?因此 GNU Parallel 的 --tty 意味着 -j1.