This question already has an answer here:

We have currently setup a cron job for our new script as below:

46 22 * * * /gzm_common/diagbat9/global/prod/chgstatus.sh /backups/diagbat9/Demantra/output/SK_ITEM_EXTRACT_MFGPRO_$(date +%m%d%y).txt

It takes the file with .txt as extension as a parameter. When the cron job executed, the file did not get created. This is what we got of the file at 22:46 pm:


and this is a zero byte file, whereas it should contain a lot of data. Shall I try putting the entire filepath and name in double quotes?

marked as duplicate by Gilles shell-script Aug 22 '14 at 22:08

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.

  • Did you get an emails from cron complaining of errors (and if not, is email properly configured on your box so that you would get them, had it sent any?) – derobert Aug 22 '14 at 11:18

You need to escape the percent characters using a backslash:

.../SK_ITEM_EXTRACT_MFGPRO_$(date +\%m\%d\%y).txt

From the crontab(5) man page from the ISC implementation of cron:

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 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. There is no way to split a single command line onto multiple lines, like the shell's trailing "\".

  • Thank you so very much for your kind and fast replies, really appreciate it. I have done teh change in our crontab and will wait for the results tomorrow. Will let u know how it goes. – arpita dhote Aug 22 '14 at 12:04
  • Dear Seniors, it worked, its now funtioning perfectly. Many many thanks for your help! – arpita dhote Sep 10 '14 at 10:27

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