rsync fails in cron - ssh key prob for rsync?
Greetings
I'm using Ubuntu 10.04 LTS server and Postgresql 8.4. I have a .sh script that is run by cron every other hour. That works fine. The .sh script includes an rsync command that copies a postgresql dump .tar file to a remote archive location via ssh. That fails when run by cron; I think because it is (quietly) asking for the remote user's password (and not getting it). I set up the public/private ssh key arrangement. The script succeeds when run manually as the same user that the cron job uses, and does not ask for the password. I am able to ssh to the remote server from the source server (using the same username) and not get the password prompt (both directions), so why doesn't rsync work? I even put a .pgpass file in the root of that user's directory with that user's password, and the user/password are identical on both servers. I think the problem is rsync is not able to use the ssh key correctly. I tried adding this to my script but it didn't help. Code:
# start ssh-agent so don't need to enter passwords manually Code:
rsync -v -u -a -e "ssh -i /home/postgres/.ssh/id_rsa" --progress --stats $BACKDIR $USER@$DEST:$DESTDIR Code:
0 */2 * * * postgres /home/postgres/backups/BST_postgres_backup_service.sh private key file - LOCAL (600) authorized_keys - LOCAL (700) authorized_keys - REMOTE (600) .ssh directory - BOTH (700) thank you for your help! |
Do you get any log output from the cron job? If not, try adding something like
Code:
> /tmp/rsynclogfile 2>&1 |
i put that line into the cron job and got this error in rsynclogfile:
Quote:
|
It looks like permission problems, but you said you can run it successfully from the command line? What is the log output when you copy your cron line to a terminal and run it?
|
That succeeds when i do it manually.
I entered: Code:
sudo bash ./BST_postgres_backup_service.sh > /tmp/BST_postgres_backup_service 2>&1 Quote:
Code:
sudo chmod 777 ~/backups Code:
sudo: no tty present and no askpass program specified |
It ran fine when you did
Code:
sudo bash ./BST_postgres_backup_service.sh > /tmp/BST_postgres_backup_service 2>&1 Code:
postgres /home/postgres/backups/BST_postgres_backup_service.sh |
Hurray for you and your help. You pointed me in the right general direction. What I finally had to do was remove "sudo" from in front of the pg_dump and tar commands in my script. apparently by using sudo, i was changing the user that ran the command, and thus it didn't run correctly from cron (although manually it had no trouble).
FIXED |
All times are GMT -5. The time now is 08:39 PM. |