Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ubuntu 9.10

crontab -l

0 1 * * * /root/cron/rsync-93.193.99.111 &> /root/cron/rsync-93.193.99.111.log
0 3 * * * tail -100 /root/cron/rsync-93.193.99.111.log | msmtp me@myemail.com

ls -l /root/cron/rsync-93.193.99.111.log

-rw-r--r-- root root /root/cron/rsync-93.193.99.111.log

The rsync-93.193.99.111.log 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

2 Answers 2

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-93.193.99.111 > /root/cron/rsync-93.193.99.111.log 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-93.193.99.111 >/root/cron/rsync-93.193.99.111.log 2>&1; tail -100 /root/cron/rsync-93.193.99.111.log | msmtp me@myemail.com

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

MAIL=me@myemail.com
0 1 * * * /root/cron/rsync-93.193.99.111 2>&1 | tee /root/cron/rsync-93.193.99.111.log | 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

 
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.