Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
06-11-2015, 12:11 PM
|
#1
|
LQ Newbie
Registered: Jun 2015
Posts: 4
Rep: 
|
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.
Last edited by quickbeard; 06-12-2015 at 02:36 PM.
|
|
|
06-11-2015, 02:59 PM
|
#2
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
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!
|
|
|
06-11-2015, 03:05 PM
|
#3
|
LQ Newbie
Registered: Jun 2015
Posts: 4
Original Poster
Rep: 
|
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!
Last edited by Tinkster; 06-11-2015 at 05:59 PM.
Reason: Not that it matters, he's probably getting probed 500 times a day already ... :D
|
|
|
06-11-2015, 05:07 PM
|
#4
|
LQ Guru
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,391
|
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
Last edited by Tinkster; 06-11-2015 at 05:59 PM.
|
|
1 members found this post helpful.
|
06-11-2015, 05:33 PM
|
#5
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
I have asked a moderator to obfuscate the IP address in your first post for you.
|
|
|
06-11-2015, 06:00 PM
|
#6
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Quote:
Originally Posted by Habitual
I have asked a moderator to obfuscate the IP address in your first post for you.
|
I did, as a show of good will =}
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
|
|
|
06-12-2015, 10:24 AM
|
#7
|
LQ Newbie
Registered: Jun 2015
Posts: 4
Original Poster
Rep: 
|
Quote:
Originally Posted by Habitual
I have asked a moderator to obfuscate the IP address in your first post for you.
|
Quote:
Originally Posted by Tinkster
I did, as a show of good will =}
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
|
Thank you very much, Habitual and Tinkster!
Quote:
Originally Posted by jailbait
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
|
Hey Steve, I have tried your solution but it did not work as well. By the way, I think the problem is somehow crontab cannot make a connection through SSH because when I added " rsync -av --delete /backup1/ /backup2/" (local backup on 1 computer) to crontab, it worked. Thank you for your help but I still need more help in this case.
Once again, thank you guys for your assistance,
- Minh.
Last edited by quickbeard; 06-12-2015 at 10:25 AM.
|
|
|
06-12-2015, 02:37 PM
|
#8
|
LQ Newbie
Registered: Jun 2015
Posts: 4
Original Poster
Rep: 
|
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.
|
|
|
06-12-2015, 06:29 PM
|
#9
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by Tinkster
I did, as a show of good will =}
|
Thanks.
Quote:
Originally Posted by Tinkster
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 ...
|
Yes, this is true. I was hoping to impart to the OP a "best practice" that is usual with posting IPs on public forums. No need to add to the fray!
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 05:31 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|