I have a problem with my backup script which is using keychain. The script works fine when fired via command line but doesn't work as expected when called via cron (does not transfer any data to the remote host). Both servers are running Ubuntu Server 14.04 LTS. My id_rsa
use empty passphare, I can connect to the remote host without any password.
Cron task:
* * * * * bash /home/kris/sync.sh
Script:
#!/bin/bash
source $HOME/.keychain/${HOSTNAME}-sh
rsync -avz --delete --log-file=/home/kris/rsync.log /var/www/owncloud/data/ [email protected]:/var/www/owncloud/data/
Output:
/home/kris/sync.sh: 2: /home/kris/sync.sh: source: not found
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.0]
.profile :
/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/${HOSTNAME}-sh