homepage Welcome to WebmasterWorld Guest from 54.227.67.210
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
rsync and ssh not working with cron
thecoolone




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

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

 

MattyMoose




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

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

thecoolone




msg:3173160
 7:48 am on Nov 30, 2006 (gmt 0)

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

thecoolone




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

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)
"

StupidScript




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved