5

Having problems with the retry command when paired with rsync. retry is a Debian package and states it can "Repeat command until a criteria is met, usually success.". Trying to use it with rsync on a connection that can sometimes fail. However it always gives the same error: giving up: No such file or directory:

retry '/usr/bin/rsync -av source destination'
retry: Could not execute 'rsync -av source destination', giving up: No such file or directory

Both source and destination exist. I've tried using the absolute path, single and double quotes, quotes around paths, and paths as variables, but none work. I can use the approach from this solution but it is rather cumbersome when doing several directories. Is there something I am missing?

2
  • Why not check $? within a while loop? Commented Jul 19, 2023 at 19:23
  • @RonJohn Yeah, that's what this solution does. But if you want a delay after failure and retry count, having retry is a lot easier/cleaner--especially if you have several rsync commands in a script. Commented Jul 19, 2023 at 22:02

2 Answers 2

9

The problem is that retry tries to execute a file called '/usr/bin/rsync -av source destination' (including the spaces in the middle).

In order to tell retry that rsync is the command, and -av ,source, and destination are the parameters that belong to the rsync command, you'll need to run it the following way:

retry -- /usr/bin/rsync -av source destination

The reason you'll need the -- (double dash) is to signify the end of command options and beginning of positional arguments. Without the -- before the command, retry will think that -av is one of it's command options, and will throw the following error:

retry: invalid option -- 'a'
8

I can see two or maybe three problems here. (And thank you for the link to retry; I haven't come across it before.)

  1. The target command is parsed "as usual" with spaces between the command and each of its arguments. Quoting the entire command means that retry will try and execute that as a command without any parameters:

    retry 'rsync -av src dst'
    retry: Could not execute 'rsync -av src dst', giving up: No such file or directory
    

    The fix here is to avoid quoting the command and its parameters in its entirety.

  2. Removing the quotes still generates an error, but this time it's because retry is trying to process the -av arguments that are intended for `rsync:

    retry rsync -av src dst
    retry: invalid option -- 'a'
    …
    

    The fix here is to use a double dash (--) after the parts specific to retry so that it stops trying to process further parameters:

    retry -- rsync -av src dst
    
  3. Running this to successful completion will result in you ending up with src under dst:

    ls dst
    src
    

    If you want dst to have the contents of src then include a trailing slash on src/:

    retry -- rsync -av src/ dst
    

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.