Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my in the home directory of my backup user

$ cat
  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 ./ as backup user on the shell it works as it should (passwordless)

$ ./
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

 <desc>run backup to nas</desc>

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
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. – fdafgfdgfagfdagfdagfdagfdagfda 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


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.