[SOLVED] - RSYNC not executing via CRON



The below error was faced and tried for online answers, made my head to heat for couple of days and finally i was able to crack the solution for the below issue.

umasarath@ubuntu:~$ tail -50 cron_alc.log
Cronjob started for back-up files
+ rsync -v umasarath@xx.xx.xx.xx:/tmp/compressed_logfiles/*.zip /home/umasarath/archive/
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(601) [Receiver=3.0.7]

umasarath@ubuntu:~$

Please follow the below steps inorder to avoid the above error.

My script contains the below code.

umasarath@ubuntu:~$ cat transfer_files.sh
#!/bin/sh
set -xv
echo "Cronjob started for back-up files" `date`
/usr/bin/rsync -vv umasarath@xx.xx.xx.xx:/tmp/compressed_logfiles/*.zip /home/umasarath/archive/
echo "Cronjob ended for back-up files from PROD to CI" `date`
The above script contains 2 echo commands and one rsync command. Just wanted to have timestamps before and after rsync command. 

  • Please use the steps to configure SSH keys in source and destination server.
  • Give the full path of the rsync(/usr/bin/rsync) command in the script.
  • Don't give the SOURCE directory with ssh command. Most of the blogs recommended to use the below syntax which didn't work for me.
    /usr/bin/rsync -vv "ssh -i umasarath@xx.xx.xx.xx:/tmp/compressed_logfiles/*.zip" /home/umasarath/archive

Placing my file in cron.


umasarath@ubuntu:~$ crontab -e
# m h  dom mon dow   command
00 00 * * * cd /home/umasarath/autotransfer;/bin/sh transfer_files.sh >>/home/umasarath/autotransfer/log/cron.log 2>&1
umasarath@ubuntu:~$
The above entry in cronjob was to run the transfer_files.sh on every Wednesday at 12AM.

When my script was executed via cron, there is no error message displayed in cron_alc.log and the script ran successfully without any issues.


Please try and explore yourselves. Kindly provide your feedback on this article.



Comments

  1. are you here under a quota system ?

    ReplyDelete
  2. Worked like a charm!. Thank you!

    ReplyDelete
  3. I still got this:
    Permission denied (publickey).
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]

    I can log in using public keys from the command line so I do have access. But I'm using root as the ssh password while I'm not logged as root, can that be the problem?

    ReplyDelete
    Replies
    1. Hey. I'm getting the same error. Did you get a fix?
      Permission denied (publickey).
      rsync: connection unexpectedly closed (0 bytes received so far) [sender]
      rsync error: unexplained error (code 255) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [sender=2.6.9]

      Delete
  4. thank you!! follow your instructions and work fantastic!

    ReplyDelete

Post a Comment

Popular posts from this blog

RSYNC command without authentication - 8 simple steps

Failed to load Main-Class manifest attribute from HelloWorld.jar - SOLVED