-   Linux - Newbie (
-   -   scp does not work with cron jobs (

yogendrarawat 09-15-2005 02:56 AM

scp does not work with cron jobs

I have written a shall script which creates a tar file and scp to remote machine. It is working fine if i run this script manualy (./ but if i execute this using cron jobs it does every thing othre then scp part of it .

file name is
cd /var/BACKUP
tar -cvf cvsroot.tar /var/cvsroot
#tar -cvf cvsroot.tar cvsbackup.txt
gzip cvsroot.tar
/usr/bin/scp cvsroot.tar.gz root@$(date +%Y%m%d-%H%M%S).tar.gz
echo "Backup of cvsroot has been copied in form of .tar.gz file"
mv cvsroot.tar.gz cvsroot-$(date +%Y%m%d-%H%M%S).tar.gz
mail -s "CVS server backup" < cvsbackup.txt

Please help.


Yogendra Rawat

blindcoder 09-15-2005 03:13 AM

do you have to enter a password to connect to the other machine? which user runs the cronjob? which user runs the script manually?


tuXfree 09-15-2005 03:34 AM

This will allow your server not to authenticate in the backup server:

Do this in the machine that has your cronjob

mkdir p /root/.ssh
chmod 0700 /root/.ssh
ssh-keygen t dsa f /root/.ssh/id_dsa P ''

copy /root/.ssh/ to the backup server

then do this in your backup server
cat >> /root/.ssh/authorized_keys2
chmod 0600 /root/.ssh/ authorized_keys2

All times are GMT -5. The time now is 09:06 AM.