Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Getting rsync to work with cron

  1. #11
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    if I use sudo crontab -e and add my line do I save it as /tmp/crontab.03oj7y or do I rename it? If so where do I put it?

  2. #12
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,737
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Getting rsync to work with cron

    Leave it as it is.

    Check if was save OK by running:
    Code:
    sudo crontab -l
    Regards.

  3. #13
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    The save is ok.

    The current line I have entered in sudo crontab -e is:

    15 53 * * * /ibackup/daily.sh >/ibackup/cron.log 2>&1

    Once again no backup. The cron.log file says this:

    Password: rsync: connection unexpectedly closed (o bytes received so far) [sender]
    rsync error: error in rsync protocol data stream (code 12) as io.c(605) [sender=3.0.9]

  4. #14
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    This was asked of me on another rforum:

    Another possibility: Could it be that the "ibackup" module on the remote machine requires entering a password and that you have set the variable RSYNC_PASSWORD in your login shell?

    If so, please be aware that cron does not set up your standard environment, so this variable will certainly be unset when the script runs from cron.

    Does anyone have any idea what they are saying? Does this help anyone?

  5. #15
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Getting rsync to work with cron

    How have you set up the password for your rsync command?

    When you run the command from a terminal do you have to type in a password or have you set up key-based authentication?
    Cheesemill

  6. #16
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,737
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Getting rsync to work with cron

    Could you post the content of your /etc/rsyncd.conf file?

    Also, have you tried anonymous sync? That is omitting the username, something like:
    Code:
    rsync -r -v -z -t /ppp  <my ip>::/ibackup
    Regards.

  7. #17
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    I now have a solution from another forum. It is posted below for everyone to see. Thanks

    __________________________________________________ ______________________________________________

    OK,

    it's neither possible for commands/scripts started by cron to ask you anything, nor is it possible for those commands/scripts to get an answer.

    Reason: the command shell started by cron to run the command/script inside does not have an associated terminal to display the password prompt or to accept an answer.

    So you must provide the password by other means.

    1.) You could add

    export RSYNC_PASSWORD=password

    to the script daily.sh, in a line of its own just below "'!/bin/sh", like

    #!/bin/sh
    export RSYNC_PASSWORD=password
    /usr/bin/rsync -r -v -z -t /ppp <my username>@<my ip>::ibackup

    This is obviously insecure, because the password appears in clear text in the script, and everybody who can read the script can read the password.

    2) Add "--password-file=/path/to/password_file" to the rsync options, like

    /usr/bin/rsync -r -v -z -t --password-file=/path/to/password_file /ppp <my username>@<my ip>::ibackup

    and create the file /path/to/password_file. It should contain just the password as a single line. Make the file owned by the user who starts the script, and make it read/writeable only by that user, e.g.

    chown myuser /path/to/password_file
    chmod 600 /path/to/password_file

  8. #18
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    12,625
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Getting rsync to work with cron

    Papibe's suggestion would also work, but you must be running rsync in "daemon mode" on the remote machine.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  9. #19
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    594
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Getting rsync to work with cron

    I include a path in my crontab schedule which tends to fix any forgotten FQ paths. Example here. If interested in how I setup servers, check my sig for more examples.

    EDIT: Sorry, didn't see the 2nd page.

    I handle my crontab schedule a bit differently. I have my crontab schedule saved in a file, which then gets backed up and archived. Whenever I make a change to my schedule, I make it to the file and then run crontab to load that file for the specific user (root in my case). I've had issues in the past and have lost my schedule due to fat-fingering the crontab command so I like modifying it in the safest way possible.

    Example, schedule file located @ /var/data/crontab.root

    Here are the steps I typically do to change a schedule:

    Code:
    cp /var/data/crontab.root /var/data/2013-08-17-crontab.root.bak
    vi /var/data/crontab.root   (* make my changes, save and exit *)
    crontab -u root /var/data/crontab.root
    Last edited by LHammonds; August 29th, 2013 at 01:52 PM.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •