简体   繁体   English

使用多个 `rsync` 无需等待完成

[英]Using multiple `rsync` without waiting completion

I have this code below which loops rsync several times in different directories:我在下面有这段代码,它在不同的目录中多次循环rsync

for (( i=0; i<6; i++ )); do

    rsync /source-${i} /remote-destination
    
done

However there is a problem: when it executes the first rsync , it asks me the password of the remove server and then it starts transfering the files.但是有一个问题:当它执行第一个rsync时,它会询问我删除服务器的密码,然后它开始传输文件。 Only after it finishes transfering all the files it executes the loop a second time, asks me the password of the remote server again (no problem, I can afford typing the password every single time) and then I need to wait the transfer to happen so it can continue.只有在它完成所有文件的传输后,它才会第二次执行循环,再次询问我远程服务器的密码(没问题,我可以负担得起每次都输入密码)然后我需要等待传输发生所以它可以继续。

I would like the loop to continue, without waiting... I tried using the & char at the end of the command line to send it to background however if I do that, I cant type the password of the remote server!我希望循环继续,无需等待...我尝试在命令行末尾使用& char 将其发送到后台,但是如果我这样做,我无法输入远程服务器的密码!

Any idea how I can solve this?知道我该如何解决这个问题吗? I really want to type myself the password every single time, this is not a problem.我真的很想每次都自己输入密码,这不是问题。 The problem is that or the loop waits every single rsync to be completed or it sends the password prompt to the background if I use & .问题是,或者循环等待每个rsync完成,或者如果我使用& ,它将密码提示发送到后台。

Look into the rsync online man page , and it has an opinion called --password-file .查看rsync在线手册页,它有一个名为--password-file的意见。

Here are some original texts:以下是部分原文:

You can avoid the password prompt by setting the environment variable RSYNC_PASSWORD to the password you want to use or using the --password-file option.您可以通过将环境变量 RSYNC_PASSWORD 设置为您要使用的密码或使用 --password-file 选项来避免密码提示。 This may be useful when scripting rsync.这在编写 rsync 脚本时可能很有用。

This is really an ssh question.这真的是一个ssh的问题。 You have to create ssh keys and copy them to the remote host - see here for some good directions.您必须创建 ssh 个密钥并将它们复制到远程主机 - 请参阅此处以获得一些好的指导。

Until you can do:直到你可以做到:

$ ssh remotehost hostname
remotehost

without entering a password rsync will require a password.不输入密码 rsync 将需要密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM