Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is my rsync.sh in the home directory of my backup user

$ cat rsync.sh
  #!/bin/sh
  rsync -avvvz --stats --log-file="/var/log/rsync_client.log" -e "ssh -i /mnt/stor0/backup/backup-rsync-key" /mnt/stor0/home/ nas@remotehost:/mnt/backup/

when I run ./rsync.sh as backup user on the shell it works as it should (passwordless)

$ ./rsync.sh
opening connection using: ssh -i /mnt/stor0/backup/backup-rsync-key -l nas remotehost rsync --server -vvvlogDtprze.iLsf . /mnt/backup/
sending incremental file list
[sender] make_file(.,*,0)
.
.
.
list of files to backup

Now my cronjob

<job>
 <enable/>
 <uuid>1c7ad7f4-0daa-477b-9e7b-eb7e5861e3d3</uuid>
 <desc>run backup to nas</desc>
 <minute>0</minute>
 <hour>4</hour>
 <day/>
 <month/>
 <weekday>1</weekday>
 <weekday>3</weekday>
 <weekday>5</weekday>
 <all_mins>0</all_mins>
 <all_hours>0</all_hours>
 <all_days>1</all_days>
 <all_months>1</all_months>
 <all_weekdays>0</all_weekdays>
 <who>backup</who>
 <command>/mnt/stor0/backup/rsync.sh</command>
</job>

When I try to run the job, it fails and client.log shows

rsync error: unexplained error (code 255) at io.c(605) [sender=3.0.9]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]

Why is the command running when I execute it manually and why does it fail as cronjob on NAS4Free?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

When you run the command manually, all your own environment settings will be used. When you run it from cron, neither your environment settings nor e.g. your ssh agent settings will be available to the script.

In this case, since you're using SSH as a transport agent, I'd guess that something goes wrong with your ssh connection when you run it from cron. If you're normally using an ssh agent, you'll need to make sure that that information is available as environment variables to the script. If you're instead using a key with no password, there's something else that makes the connection fail. Is ssh in the $PATH used by cron? Can you make the connection using "ssh -v" to get further information?

share|improve this answer
    
Thanks I found the problem. You been generally right, it was a problem with ssh, but a little different. If you tell the NAS4Free Cron GUI to run the job as backup user, it still starts it as root. However root did not have the remote in its known hosts therefore the ssh connection failed. I noticed that, when I routed the output of the command via >> /var/log/rsync-cron.log and saw, that rsync-cron.log was created by root. So either I have to add the host to roots known ssh hosts, or I just use su backup -c 'rsync...'. It works now. –  Jherek Carnelian Mar 26 '13 at 10:12
    
Thanks for the follow-up! I'll make a note to next time ask if the cron job is being run as the same user :-) –  Jenny D Mar 26 '13 at 13:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.