1

Why does this rsync command running in a cron fail and how to debug it and fix?

unset SSH_AUTH_SOCK && unset KRB5CCNAME && rsync -hvru -e "ssh -p 34503 -i /root/.ssh/id_rsa_rsyncBACKUP" --progress /home/kristjan/* kristjan@192.168.1.213:/BACKUP/Backup/Kundrum/ >> /home/kristjan/logs/rsyncCRON.log

$crontab -l
# Edit this file to introduce tasks to be run by cron.
# m h  dom mon dow   command
0 5 * * 1 /home/kristjan/bin/checkSystem
00 02 * * * unset SSH_AUTH_SOCK && unset KRB5CCNAME && rsync -hvru -e "ssh -p 34503 -i /root/.ssh/id_rsa_rsyncBACKUP" --progress /home/kristjan/* kristjan@192.168.1.213:/BACKUP/Backup/Kundrum/ >> /home/kristjan/logs/rsyncCRON.log
15 23 * * 7 /home/kristjan/bin/unhideCheckSystem

The error is (which I got from a email):

ssh: connect to host 192.168.1.213 port 34503: No route to host

rsync: connection unexpectedly closed
rsync error: unexplained error (code 255) at io.c (235)

The command works if I run it in the shell directly.

EDIT:

from ssh file on remote = AllowUsers kristjan root and cron is run by root

EDIT:

Since posting this question I changed the command and it works that way but I'm still interested in knowing why the first didn't work.

Here is the working command in root's cron:

0 5 * * 1 /home/kristjan/bin/checkSystem
00 02 * * * unset SSH_AUTH_SOCK && unset KRB5CCNAME && rsync -hvru -e "ssh -p 34503 -i /root/.ssh/id_rsa_rsyncBACKUP" --progress /home/kristjan/* kristjan@192.168.1.213:/BACKUP/Backup/Kundrum/ | mail -s "Backup Home report for `uname -n`" myMailATTgmail.com

EDIT because of duplicate flag:

If this was a question about basically doing redirection wrong(not saying I didn't) then why this line in the original question:

The command works if I run it in the shell directly.
  • What's the log / failure? – Jeff Schaller Apr 20 at 3:56
  • @JeffSchaller no such directory or file, my system is Debian Stretch all updates – somethingSomething Apr 20 at 4:00
  • 1
    In a previous comment, you first said that you got a "no such file or directory" error. That error should have included 1) what program generated it, and 2) what file was not found. Could you say something about this? – Kusalananda Apr 20 at 20:58
  • 1
    Possible duplicate of How to redirect output to a file from within cron? – thecarpy May 7 at 12:01
  • 1
    The possible duplicate is asking about output redirection using Bash-specific operators in a cron job. However, this question is not using Bash-isms, just the regular POSIX append operator, >>. – Anthony Geoghegan May 8 at 10:47

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.