rsync doesn't work with crontab.
Hi everyone,
I am trying to transfer data between 2 CentOS 6.6 computers through SSH without requiring password. I have successfully set up a keypair with no password and when I execute the below command on command-line interface, it totally worked: rsync -av --delete -e ssh /backup/ root@xxx.xxx.20.209:/backup/ However, when I add this command to crontab, it wasn't executed: 42 11 * * * rsync -av --delete -e ssh /backup/ root@xxx.xxx.20.209:/backup/ It's pretty weird and I don't know what gone wrong. Plsease help me with this issue. Thank you very much. |
What does /var/log/cron say about this?
Warning: obfuscate that IP, NOW. Re-edit your post and sub first 2 octets with xxx and yyy eg: xxx.yyy.20.209 Edit: And welcome to LQ! |
Hi Habitual,
It says: Jun 11 14:57:46 mu-020200 crontab[1304]: (root) BEGIN EDIT (root) Jun 11 14:58:15 mu-020200 crontab[1304]: (root) REPLACE (root) Jun 11 14:58:15 mu-020200 crontab[1304]: (root) END EDIT (root) Jun 11 14:59:01 mu-020200 crond[1211]: (root) RELOAD (/var/spool/cron/root) Jun 11 14:59:02 mu-020200 CROND[1310]: (root) CMD (rsync -av --delete -e ssh /backup/ root@xxx.xxx.20.209:/backup/) Seems like ther's no error. When I check /var/spool/cron/root, it says: From root@mu-020200.dhcp.missouri.edu Thu Jun 11 14:59:22 2015 Return-Path: <root@mu-020200.dhcp.missouri.edu> X-Original-To: root Delivered-To: root@mu-020200.dhcp.missouri.edu Received: by mu-020200.dhcp.missouri.edu (Postfix, from userid 0) id C3E617FFA0; Thu, 11 Jun 2015 14:59:22 -0500 (CDT) From: root@mu-020200.dhcp.missouri.edu (Cron Daemon) To: root@mu-020200.dhcp.missouri.edu Subject: Cron <root@mu-020200> rsync -av --delete -e ssh /backup/ root@128.206.20.209:/backup/ Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated X-Cron-Env: <LANG=en_US.UTF-8> X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <HOME=/root> X-Cron-Env: <PATH=/usr/bin:/bin> X-Cron-Env: <LOGNAME=root> X-Cron-Env: <USER=root> Message-Id: <20150611195922.C3E617FFA0@mu-020200.dhcp.missouri.edu> Date: Thu, 11 Jun 2015 14:59:22 -0500 (CDT) Permission denied, please try again.^M Permission denied, please try again.^M Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).^M rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6] But when I typpe the command on CLI, there is no error like this, the file was sent succesfully. That's very weird. Thank you for your help! |
Crontab has a different PATH than root or user. Try using the full path name when you execute rsync in crontab, for example:
42 11 * * * /usr/bin/rsync -av --delete -e ssh /backup/ root@xxx.xxx.20.209:/backup/ You can find out where rsync is located with: which rsync ------------------------------ Steve Stites |
I have asked a moderator to obfuscate the IP address in your first post for you.
|
Quote:
In all honesty I don't think that (in this day) it makes a difference. Put a new machine w/ a public IP up and it will be probed in under a minute anyway ... Cheers, Tink |
Quote:
Quote:
Quote:
Once again, thank you guys for your assistance, - Minh. |
Hey guys,
I have figured out the problem. It seems that CLI and crontab run on different environments, so crontab need to be told where the private key is. I simply added the location of private key on the command: 42 11 * * * rsync -av --delete -e "ssh -i /root/.ssh/id_rsa" /backup/ root@xxx.xxx.20.209:/backup/ and it works now. Thank you for all your help. - Minh. |
Quote:
Quote:
We wouldn't advertise we have a home security system, now would we? ;) who knows. xxx.yyy.20.209 (the original post IP) may not have even been "his" and if that's the case, he's smarter that I gave him credit for. No offense to quickbeard. Have a Great Weekend! |
All times are GMT -5. The time now is 07:08 PM. |