I have a script that is in backup.sh file (chmod 775) :
rsync -e 'ssh -p 31234' -avlz --delete --stats --progress --copy-links [email protected]:/home/admin/rsync /home/myname/rsync/foo/
When I call it manually, everything works well (and I don't have to enter my passphrase). But when I call it from cron, it just doesn't work.
I used the same setup on the computer of my coworker (who has the same access than me) and it works well.
What's wrong?
I have my passpharseless ssh login setup. I use a command like the following:
rsync --delete -auve 'ssh -i /home/red/.ssh/cron_jobs_key' red@othermachine:/source/dir1 /dest/dir2
The key here is "
-i /home/red/.ssh/cron_jobs_key
" where I have setup an ssh login without a password. Otherwise, I would have to enter my ssh key when I login to my local machine. I generated this ssh key specifically for cron jobs.Some hints:
by mentioning that you dont't have to enter the passphase, I would assume that you are using ssh-agent to enter it once per session.
This won't work from cron as cron has no access to your SSH_AUTH_SOCK variable because it has been started at machine startup, not within your current session.
If you want this to work, you'll have to use a passphraseless key, thats probably what your coworker is using.