【问题标题】:Using GNU Parallel and rsync with passwords?使用 GNU Parallel 和 rsync 密码?
【发布时间】:2016-05-10 02:41:58
【问题描述】:

我见过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,它报告了 wlan0 上所有流量的 0 Kb/s,这是唯一的我这里有一个。

问题是 - 我登录的服务器只接受带密码的 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 并行 20160422”。

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

那么,我如何使用 GNU 并行,使用密码运行多个 rsync 任务?

【问题讨论】:

    标签: shell parallel-processing rsync gnu-parallel


    【解决方案1】:

    使用sshpass:

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

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

    【讨论】:

      猜你喜欢
      • 2019-01-08
      • 1970-01-01
      • 2013-07-30
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多