VanagaS VanagaS -4 years ago 142
Linux Question

watch with rsync fails with permission denied, while rsync alone just works fine

I'm trying to sync my files to cloud:

rsync -avPze "ssh -i /path/to/my/key" [source] [destination]

this works successfully for me.

However, when I try to use the same command with
in order to sync automatically every couple minutes, it doesn't work and throws error:

watch -n120 rsync -avPze "ssh -i /path/to/my/key" [source] [destination]


Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]

Any idea what is going on?

Answer Source

Enclosing the whole rsync command within quotes, does the trick.

watch -n120 "rsync -avPze 'ssh -i /path/to/my/key' [source] [destination]" 

Observed from strace output:

execve("/usr/bin/watch", ["watch", "-n120", "rsync", "-avPze", "ssh -i '/path/to/my/key'", "source"..., "destination"...], [/* 21 vars */]) = 0

While rsync has properly initiated with source and destination being the far end arguments, and path is full path to key, permission denied error is misleading.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download