SCP/RSYNC don't work in Crontab but work when run standalone

I need to copy a backup file to a backup server everyday. I am using PublicKey SSH authentication.

All of the things work but not together:

If I run this line in crontab

rsync /home/ubuntu/*date_backup.archive* ssh centos@10.x.x.x/home/centos/backup

This works and sends the backup correctly

But since the date in the filename of the .archive changes, I need to run a script. Then I create rsync_backup.sh

#!/bin/bash
date= ...
rsync /home/ubuntu/*date_backup.archive* ssh centos@10.x.x.x/home/centos/backup

Then, if I run this via terminal with bash rsync_backup.sh, it works and sends the backup correctly

BUT if I put

* * * * * bash /home/ubuntu/rsync_backup.sh

or

* * * * * bash /home/ubuntu/rsync_backup.sh

The backup doesn't reach the destination host.

Also, if I put in the script another test line on local (mkdir /home/centos/test) and launch with crontab, it works!

I tried also with SCP, still the same results!

Do you have some ideas? Source machine is Ubuntu and Destination is Centos

Many thanks in advance

2 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like