This question already has an answer here:

I'm trying to learn a little about cron.

I edited crontab -e to have this line:

 */10 * * * * /usr/bin/touch /home/dkb/Desktop/test.txt

It works and I see test.txt changing its "Date Modified" value every ten min in Thunar and there are corresponding entries in /var/log/syslog:

Mar 13 10:50:01 dkb-lappy CRON[3978]: (dkb) CMD (/usr/bin/touch /home/dkb/Desktop/test.txt)
Mar 13 11:00:01 dkb-lappy CRON[4066]: (dkb) CMD (/usr/bin/touch /home/dkb/Desktop/test.txt)
Mar 13 11:10:01 dkb-lappy CRON[4099]: (dkb) CMD (/usr/bin/touch /home/dkb/Desktop/test.txt)

But, if I use

*/10 * * * * /usr/bin/touch /home/dkb/Desktop/$(date +%H:%M:%S).txt  

no file is created at all in ~/Desktop and syslog has this:

Mar 13 11:30:01 dkb-lappy CRON[4241]: (dkb) CMD (/usr/bin/touch /home/dkb/Desktop/$(date +)
Mar 13 11:30:01 dkb-lappy CRON[4240]: (CRON) info (No MTA installed, discarding output)
Mar 13 11:40:01 dkb-lappy CRON[4251]: (dkb) CMD (/usr/bin/touch /home/dkb/Desktop/$(date +)
Mar 13 11:40:01 dkb-lappy CRON[4250]: (CRON) info (No MTA installed, discarding output)

I checked that /usr/bin/touch /home/dkb/Desktop/$(date +%H:%M:%S).txt works properly in the terminal.

So what am I doing wrong?

marked as duplicate by Anthon, terdon, jasonwryan, Zelda, slm Mar 13 '14 at 11:52

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.


crontab treats % specially. You need to escape it with a backslash.

From man 5 crontab:

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.

Thus, to get date to work properly:

*/10 * * * * /usr/bin/touch /home/dkb/Desktop/$(date +\%H:\%M:\%S).txt  

Not the answer you're looking for? Browse other questions tagged or ask your own question.