Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

./script &>> log.txt

I get a nice logfile, but if I have the same command executed by cron, lets say the crontab looks like this:

* * * * * '/home/user/script &>> /home/user/log.txt'

the log.txt will just be empty, I tried " and ' and ` and no ticks to enclose the command, any idea why the streams won't get written into the file?

share|improve this question
up vote 6 down vote accepted

Chances are that the shell that cron uses doesn't support the shorthand redirection operator &>> that Bash supports.

You should use the portable form which is supported in the Bourne shell and others:

* * * * * /home/user/script >> /home/user/log.txt 2>&1

That says "append the standard output (file descriptor 1) to the file and send standard error (file descriptor 2) to the same place".

And you don't need any quotes.

share|improve this answer
+1 for also redirect the std error! No wonder it's outputting nothing. – User Jul 20 at 23:04
  1. Don't include any quotes for the command in the crontab.

  2. Consider running an environment setting script that does its own redirection, instead of relying on cron to do it.

In my experience, the less there is in the crontab file, the better. My crontab files consist of the time controls plus a simple absolute command name (ksh) and the command it is to run:

#   @(#)$Id: crontab,v 4.2 2007/09/17 02:41:00 jleffler Exp $
#   Crontab file for Home Directory for Jonathan Leffler (JL)
#Min     Hour    Day     Month   Weekday Command
0        *       *       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/hourly
1        1       *       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/daily
23       1       *       *       1-5     /usr/bin/ksh /work1/jleffler/bin/Cron/weekday
2        3       *       *       0       /usr/bin/ksh /work1/jleffler/bin/Cron/weekly
21       3       1       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/monthly
share|improve this answer
Your point #1 is a bit misleading (I guess you mean "Do not quote the whole command."). cron usually uses /bin/sh which is certainly capable of handling quoting, but the OP's quotes were used incorrectly (likewise, the redirection was not sh compatible). Some versions of cron will let crontab files specify which shell should interpret the commands, so it might be possible to use the features and syntax of your favorite shell right in a crontab entry. Though certainly I agree that keeping crontab entries simple is nice suggestion. – Chris Johnsen Mar 28 '10 at 22:31
thanks alot for the insight – gletscher Mar 29 '10 at 0:11
@Chris: yes - my statement is too sweeping and your analysis is correct. Thanks. – Jonathan Leffler Mar 29 '10 at 6:29

You must log in to answer this question.

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