1

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 [email protected]

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 ?

3
  • Whose crontab is it - root's or your own? Sep 28, 2010 at 20:52
  • login as my user, then sudo su, then crontab -e
    – user19496
    Sep 28, 2010 at 21:25
  • I'm assuming it's root's crontab
    – user19496
    Sep 28, 2010 at 21:44

2 Answers 2

2

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.

1

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 [email protected]

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

[email protected]
0 1 * * * /root/cron/rsync-93.193.99.111 2>&1 | tee /root/cron/rsync-93.193.99.111.log | tail -n 100
2
  • You might want && instead of ; to make the tail dependent on the success of the rsync rather than just the completion. Sep 29, 2010 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. Sep 29, 2010 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .