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
/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/home/.ssh
belongs to which user? How did you add the cronjob? (I'm asking, because people tend to useroot
cronjobs when they should use user cronjobs...) – pLumo Aug 8 '19 at 14:57ssh-keygen
would choose/home/user/.ssh
. – pLumo Aug 8 '19 at 15:16ssh -i /home/me/.ssh/id_rsa
(notid_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