Super User is a question and answer site for computer enthusiasts and power users. 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

Ubuntu 9.10

crontab -l

0 1 * * * /root/cron/rsync- &> /root/cron/rsync-
0 3 * * * tail -100 /root/cron/rsync- | msmtp

ls -l /root/cron/rsync-

-rw-r--r-- root root /root/cron/rsync-

The rsync- file displays zero size in Nautilus.
I get an email, but it's empty.
Running tail -100, also shows emtpty output, so the email is correct.

Why is the bash rsync script not writing anything to the file ?

share|improve this question
Whose crontab is it - root's or your own? – grawity Sep 28 '10 at 20:52
login as my user, then sudo su, then crontab -e – user19496 Sep 28 '10 at 21:25
I'm assuming it's root's crontab – user19496 Sep 28 '10 at 21:44
up vote 2 down vote accepted

I believe it's because &> is not supported in sh which is the shell that cron uses. Use the explicit form:

0 1 * * * /root/cron/rsync- > /root/cron/rsync- 2>&1

Also, you can do sudo crontab -e instead of doing sudo su then crontab -e.

share|improve this answer

I concur with Dennis's assessment of your problem. But I have a couple of other points to mention.

Most importantly, don't do this:

0 1 * * * some command
0 3 * * * some other command that should run after the first one

What if the first command takes more or less than two hours? To make sure that the second command runs when the first finished, put them on a single line:

0 1 * * * /root/cron/rsync- >/root/cron/rsync- 2>&1; tail -100 /root/cron/rsync- | msmtp

Also, you might want to take advantage of cron's automatic mailing of errors. (This assumes your system is set up properly for mail, which may not be the case if you have to run msmtp rather than mail.)
0 1 * * * /root/cron/rsync- 2>&1 | tee /root/cron/rsync- | tail -n 100
share|improve this answer
You might want && instead of ; to make the tail dependent on the success of the rsync rather than just the completion. – Dennis Williamson Sep 29 '10 at 0:01
@Dennis: For once, I felt ; was more appropriate (and if I'd allowed myself to change the spec I'd have used ||). After all the most likely use for the log is to see errors. – Gilles Sep 29 '10 at 0:35

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.