[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`
- 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:~$
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.
are you here under a quota system ?
ReplyDeleteWorked like a charm!. Thank you!
ReplyDeleteI still got this:
ReplyDeletePermission 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?
Hey. I'm getting the same error. Did you get a fix?
DeletePermission 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]
thank you!! follow your instructions and work fantastic!
ReplyDelete