Home > Mobile >  Using multiple `rsync` without waiting completion
Using multiple `rsync` without waiting completion

Time:11-27

I have this code below which loops rsync several times in different directories:

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. 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!

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 &.

CodePudding user response:

Look into the rsync online man page, and it has an opinion called --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. This may be useful when scripting rsync.

CodePudding user response:

This is really an ssh question. You have to create ssh keys and copy them to the remote host - see here for some good directions.

Until you can do:

$ ssh remotehost hostname
remotehost

without entering a password rsync will require a password.

  • Related