0

UBUNTU 16.04 Root Server.

I would like to have a crontab job run an rsync backup job every night at 2:14am. It copies a "folder" from an Ubuntu 16.04 machine to another root server in the internet. There is an ssh connection possible with a ssh key login.

The following command works in the terminal:

/usr/bin/rsync -az --delete -e ssh /home/user/folder/ [email protected]:/home/user/folder

But the following crontab job does not work:

14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ [email protected]:/home/user/folder

I am having a hard time with crontab to be honest. It always feels to be a lucky situation if the job actually works.

Can someone see from the crontab job above what I am doing wrong?

greetings, Chris

8
  • 1
    What error does the command give when running from cron? 'does not work' is not enough.
    – Soren A
    May 15, 2018 at 8:17
  • I agree that this is not enough. But where could I see what error it gives? I have no idea where to see the error message, since it'sa a cronjob. And that runs "in the background" (if it runs).
    – user822988
    May 15, 2018 at 20:43
  • redirect the output from the command with > /path/to/outfile 2>&1 and check the content of the file after cron has run the job.
    – Soren A
    May 15, 2018 at 22:38
  • Thanks for that already!. I get the error message: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
    – user822988
    May 16, 2018 at 8:56
  • I guess the Host Key error happens because it tries to connect as "root" and not as "user". I need to define the ssh user for the connection.
    – user822988
    May 16, 2018 at 9:02

2 Answers 2

1

The problem I had was that the ssh connection The Host Key verification failed.

I ran the cronjob on the crontab of root. (I added the cronjob via "sudo crontab -e".)

14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ [email protected]:/home/user/folder

It seems that the ssh connection then is established by the root user and not by the "user".

So the connection attempt is actually:

ssh [email protected]

and not

ssh [email protected]

So I added the cronjob to the crontab of the "user". (crontab -e (without sudo)).

Now the Host Key Verification works and the crontab rsync job is executed properly.

I don't know exactly if the above assumptions are correct but this solved the problem.

I hope this thread will help someone else at some stage as well.

Greetings, Chris

0

In addittion to run crontab -e as the user yo are using, you have to create a public key without passphrase.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .