12

The following crontab does not work:

# TEST LINE DOES DOT RUN
*/1 * * * * /bin/echo 'test '`/bin/date +%Y-%m-%d` >> /tmp/test

I also tried starting it with:

SHELL=/bin/bash

Update: I thought the backtick characters ` were the villains, but as the answer below clarifies the percentage % was the culprit!

muru
  • 197,895
  • 55
  • 485
  • 740
lpanebr
  • 1,277
  • Your test line will run only once each hour. That may not be what you intended for testing. – user535733 Mar 13 '14 at 23:04
  • isn't the first the minute?# m h dom mon dow command – lpanebr Mar 14 '14 at 01:04
  • You are right.. I changed to */1 to make it run every minute.The cron is running fine. There is something with the commands. It seems to be the /bin/date +%Y-%m-%d – lpanebr Mar 14 '14 at 01:49

1 Answers1

14

In /bin/date +%Y-%m-%d, you need to escape each % with \ according to this man page:

The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

DK Bose
  • 42,548
  • 23
  • 127
  • 221