Rsync when run in cron doesnt work. Rsync between Mac Os x Server and Linux Centos
Posted
by
Brady
on Server Fault
See other posts from Server Fault
or by Brady
Published on 2011-02-21T14:23:50Z
Indexed on
2011/02/21
15:27 UTC
Read the original article
Hit count: 396
I have a working rsync setup between Mac OS X Server and Linux Centos when run manually in a terminal.
I enter the rsync command, it asks for the password, I enter it and off it goes, runs and completes.
Now I know thats working I set out to fully automate it via cron.
First off I create an SSH authorized key by running this command on the Mac server:
ssh-keygen -t dsa -b 1024 -f /Users/admin/Documents/Backup/rsync-key
Entering the password and then confirming it. I then copy the rsync-key.pub file accross to the linux server and place in the rsync user .ssh folder and rename to authorized_keys:
/home/philosophy/.ssh/authorized_keys
I then make sure that the authorized_keys file is chmod 600 in the folder chmod 700.
I then setup a shell script for cron to run:
#!/bin/bash
RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/Users/admin/Documents/Backup/rsync-key
RUSER=philosophy
RHOST=example.com
RPATH=data/
LPATH="/Volumes/G Technology G Speed eS/Backup"
$RSYNC -avz --delete --progress -e "$SSH -i $KEY" "$LPATH" $RUSER@$RHOST:$RPATH
Then give the shell file execute permissions and then add the following to the crontab using crontab -e:
29 12 * * * /Users/admin/Documents/Backup/backup.sh
I check my crontab log file after the above command should run and I get this in the log and nothing else:
Feb 21 12:29:00 fileserver /usr/sbin/cron[80598]: (admin) CMD (/Users/admin/Documents/Backup/backup.sh)
So I asume everything has run as it should. But when I check the remote server no files have been copied accross.
If I run the backup.sh file in a terminal as normal it still prompts for a password but this time its through the Mac Key chain system rather than typing into the console window. With the Mac Key Chain I can set it to save the password so that it doesnt ask for it again but Im sure when run with cron this password isnt picked up.
This is where I'm asuming where rsync in cron is failing because it needs a password to connect but I thought the whole idea of making the SSH keys was to prevent the use of a password. Have I missed a step or done something wrong here?
Thanks
Scott
© Server Fault or respective owner