Welcome to WebmasterWorld Guest from 54.198.222.129

Forum Moderators: bakedjake

Message Too Old, No Replies

rsync and ssh not working with cron

     
3:00 pm on Nov 29, 2006 (gmt 0)

5+ Year Member



I setup a ssh private and public key and wrote a script that can be used by cron.
so when i execute
$ rsync -avz -e "ssh -i /home/thisuser/cron/thishost-rsync-key"
remoteuser@remotehost:/remote/dir /this/dir/
i am able to transfer the file. but with the crond trying to do the
same im getting the above mentioned error.

Now again im getting a new error:
" Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
rsync: connection unexpectedly closed (0 bytes received so far)
[receiver] rsync error: error in rsync protocol data stream (code 12)
at io.c(359)"

can anyone help me out here? whats wrong?
y can u i transfer the file manually using rsync and ssh but not with cron?

any help is always appreciated

6:11 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



when scripts are run through cron, there are often environment variables that are stripped out.

Your best bet would be to post the contents of your script to see what's going on with it. Additionally, to narrow the problem down, I'd suggest scheduling through cron a simple ssh test, to see if it's SSH that has a problem, or rsync, or otherwise.

schedule a script that runs this command:


ssh -i /home/thisuser/cron/thishost-rsync-key user@remotehost.com touch /tmp/ssh_test.txt
7:48 am on Nov 30, 2006 (gmt 0)

5+ Year Member



here is the script:
#!/bin/sh

export PATH=$PATH:/usr/local/bin
if [! -f /tmp/syncingcms ]
then
touch /tmp/syncingcms
/usr/bin/rsync -av -e /usr/bin/ssh --exclude '*.svn*' thecoolone@vtu.org:/var/www/vtu/info.vtu.org/* /var/www/testing
rm /tmp/syncingcms
fi

And this is the crontab file
MAILTO="thecoolone19@hotmail.com"
SHELL=/bin/bash
* * * * * /var/cmsfile

On executing my script for the first time i get this:
bash -x /var/cmsfile
+ export PATH=/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/thecoolone/bin:/usr/local/bin
+ PATH=/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/thecoolone/bin:/usr/local/bin
+ '[' '!' -f /tmp/syncingcms ']'
+ touch /tmp/syncingcms
+ /usr/bin/rsync -av -e /usr/bin/ssh --exclude '*.svn*' thecoolone@vtu.org:/var/www/vtu/info.vtu.org/* /var/www/testing
thecoolone@vtu.org password: "I type in the pwd"
receiving file list ... done
rsync: recv_generator: mkdir "/var/www/testing/CVS" failed: Permission denied (1 3)
rsync: stat "/var/www/testing/CVS" failed: No such file or directory (2)
rsync: recv_generator: mkdir "/var/www/testing/maths" failed: Permission denied (13)
rsync: stat "/var/www/testing/maths" failed: No such file or directory (2)
rsync: recv_generator: mkdir "/var/www/testing/maths/images" failed: No such fi le or directory (2)

And this goes on for all the files. And after its done i checked the testing directory and nothing is backed up

And another bizzare thing is when i execute $bash -x /var/cmsfile for the 2nd time again i get this msg:
+ export PATH=/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/thecoolone/bin:/usr/local/bin
+ PATH=/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/thecoolone/bin:/usr/local/bin
+ '[' '!' -f /tmp/syncingcms ']'

Only when i remove the /tmp/syncingcms file am i able to execute the script again.

can someone tell me whats happening in here?

thanx in advance

7:49 am on Nov 30, 2006 (gmt 0)

5+ Year Member



After checking the directory permission now when i execute bash /var/cmsfile
it execute without any error.

BUT when i try to execute the same script using cron i still get the same error
"Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
rsync: connection unexpectedly closed (0 bytes received so far) [receiver] rsync error: error in rsync protocol data stream (code 12) at io.c(359)
"

12:07 am on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the cronjob running as the same user you "are" when you execute from the command line?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month