Possible Duplicate:
How can I execute date inside of a cron tab job?

I made a cronjob to record a stream every friday between 23pm and midnight. Only somehow this doesn't seem to work.

the cronjob is

57 22 * * 5 timeout -s SIGINT 66m mplayer -dumpstream -dumpfile /var/www/HOA-NL/$(date +"%U-%Y").mp3 >> /home/david/HOA-NL-LOG 2>&1

This doesn't work while the following works

57 22 * * 5 echo "foo" > /home/david/barr

and the following works either (timing out echo doesn't make sense, I know. It's just an example)

57 22 * * 5 timeout -s SIGINT 66m echo "foo" > /home/david/barr

Now I'm wondering why this doesn't work.. It doesn't give me a error or a message in /home/david/HOA-NL-LOG

marked as duplicate by Gilles, Mat, Ulrich Dangel, Renan, jasonwryan Aug 19 '12 at 21:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from serverfault.com Aug 4 '12 at 3:53

This question came from our site for system and network administrators.

  • Does your command work if you run it from the CLI? – Zoredache Aug 3 '12 at 23:47

You've committed the classic error of using date +%foo in a cron job, causing you to bump into cron's most baffling feature. Clearly documented in man 5 crontab but often overlooked, here it is:

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 crontab file. 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.

Backslash your percent signs!