1

I am running this command from terminal and it works well. Files ares uploaded to the remote server without having to type any password.

rsync -avz -e "ssh -i /home/me/.ssh/id_rsa.pub" --delete /home/me/backup/bin/backup/bio root@vpsxxxxxx.ovh.net:backups_bio/ --log-file=$HOME/rsync.log

But if I run it from crontab I am getting this error :

2019/08/08 16:04:02 [3062] rsync: connection unexpectedly closed (0 bytes received so far) [sender] 2019/08/08 16:04:02 [3062] rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]

And the upload doesn't work.
Why doesn't it work when launched from Crontab?
I am using ubuntu 18.04 LTS

12
  • /home/.ssh/ and /home/backup are the real folders? Might be $HOME is not set for cron ?! You should try to use absolute paths. Also, put --log-file= in front as it's part of [OPTION...]. – pLumo Aug 8 '19 at 14:36
  • yes, they are the real folders. The log file works fine, I don't have any problem with $HOME. – thomas Aug 8 '19 at 14:56
  • 1
    and the folder /home/.ssh belongs to which user? How did you add the cronjob? (I'm asking, because people tend to use root cronjobs when they should use user cronjobs...) – pLumo Aug 8 '19 at 14:57
  • 1
    ssh-keygen would choose /home/user/.ssh. – pLumo Aug 8 '19 at 15:16
  • 2
    Shouldn't you be passing the private identity file to SSH i.e. ssh -i /home/me/.ssh/id_rsa (not id_rsa.pub)? FYI $HOME is fine; it's part of the (reduced) cron environment as described here Set environment variable UBUNTU 18.04 (bionic) - Crontab and will be expanded into an absolute path by the shell in which the job is run (/bin/sh, by default) – steeldriver Aug 8 '19 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.