LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 06-11-2015, 12:11 PM   #1
quickbeard
LQ Newbie
 
Registered: Jun 2015
Posts: 4

Rep: Reputation: Disabled
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.
 
Old 06-11-2015, 02:59 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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!
 
Old 06-11-2015, 03:05 PM   #3
quickbeard
LQ Newbie
 
Registered: Jun 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
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
 
Old 06-11-2015, 05:07 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
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.
Old 06-11-2015, 05:33 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I have asked a moderator to obfuscate the IP address in your first post for you.
 
Old 06-11-2015, 06:00 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by Habitual View Post
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
 
Old 06-12-2015, 10:24 AM   #7
quickbeard
LQ Newbie
 
Registered: Jun 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
I have asked a moderator to obfuscate the IP address in your first post for you.
Quote:
Originally Posted by Tinkster View Post
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 View Post
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.
 
Old 06-12-2015, 02:37 PM   #8
quickbeard
LQ Newbie
 
Registered: Jun 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-12-2015, 06:29 PM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Tinkster View Post
I did, as a show of good will =}
Thanks.
Quote:
Originally Posted by Tinkster View Post
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
crontab -e @reboot doesn't always work dalponis Linux - Software 6 12-09-2013 11:00 AM
Crontab doesn't work and #!/bin/bash -vx emmeteo Linux - Software 10 01-11-2013 11:36 AM
crontab -e doesn't work after upgrade gbltech Slackware 3 04-21-2009 10:42 AM
crontab -e username doesn't work BiThian Linux - General 3 10-13-2006 10:31 AM
crontab doesn't work, but everything is set correctly ttilt Linux - General 10 06-16-2005 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration